asp.net mvc - Soc in MVC which is the better design pattern for mvc for huge distributed applications -
i need create e-commerce application ,which best design model
have seen of them separating entity framework context class in seperate class library , business layer in seperate class library , data classes poco class in seperate class library project. have context class know consider example
this db created poco class
using system.componentmodel.dataannotations; using system.web.mvc; public partial class user { public int userid { get; set; } public string username { get; set; } public string password { get; set; } public string confirmpassword { get; set; } public string fullname { get; set; } public string emailid { get; set; } } [httppost] [validateantiforgerytoken] public actionresult register(user u) { if (modelstate.isvalid) { using (mydatabaseentities dc = new mydatabaseentities()) { dc.users.add(u); dc.savechanges(); modelstate.clear(); u = null; viewbag.message = "successfully registration done"; } } return view(u); } or else have create seperate class container , access?
public class user { public int userid { get; set; } public string username { get; set; } public string password { get; set; } public string confirmpassword { get; set; } public string fullname { get; set; } * public string emailid { get; set; } } in controller
public actionresult register(user u) { using (mydatabaseentities dc = new mydatabaseentities()) { user.userid= u.userid; user.username = u.username; user. password = u.password; user.confirmpassword = u.confirmpassword; user.userid= u.userid; dc.savechanges(); viewbag.message = "successfully registration done"; } } return view(u); } which better way , difference between model binding , these? why not preferred binding ef classes?
second way - when separate dal (data access layer) , viewmodels bind in controller automatically mvc better.
because if separate atleast 2 layers (i can't see bl layer in example) can change views show user information , don't mess dal layer, change mappings (you map viewmodel in register controller).
this looks insignificant if have simple view , dal logic, when project grow good, because this allow change view logic , dal logic separately.
Comments
Post a Comment