Last active
December 2, 2016 05:01
-
-
Save elderfo/48a7896b15218faa31cac63a9e30ca5a to your computer and use it in GitHub Desktop.
Original standard architecture business logic class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Project.Logic; | |
namespace Project.Controllers | |
{ | |
public class ExampleController : Controller | |
{ | |
public JsonResult GetUser(Guid userId) | |
{ | |
UserModel user = Logic.User.Get(userId); | |
return Json(user, JsonRequestBehavior.AllowGet); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Project.Data; // enternal dependency | |
namespace Project.Logic | |
{ | |
public class User | |
{ | |
public static UserModel Get(Guid userId) | |
{ | |
using (var entities = new Entities()) { | |
User user = entities.Users.Find(userId); | |
// ... transform to UserModel | |
return userModel | |
} | |
} | |
public static List<UserModel> Get(Func<Data.User, bool> predicate = null) | |
{ | |
using (var entities = new Entities()) { | |
IEnumerable<User> users = predicate == null | |
// get all users | |
? entities.Users | |
// filter user | |
: entities.Users.Where(predicate); | |
// .. transform to UserModel | |
return models; | |
} | |
} | |
public static UserModel Create(UserModel model) { ... } | |
public static void Update(UserModel model) { ... } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment