Skip to content

Instantly share code, notes, and snippets.

@elderfo
Last active December 2, 2016 05:01
Show Gist options
  • Save elderfo/48a7896b15218faa31cac63a9e30ca5a to your computer and use it in GitHub Desktop.
Save elderfo/48a7896b15218faa31cac63a9e30ca5a to your computer and use it in GitHub Desktop.
Original standard architecture business logic class
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);
}
}
}
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