c# - Two tables one context to save changes -
i have defined 2 tables , initialized necessary data entries in db tables.
here userscontext
public class userscontext : dbcontext { public userscontext() : base("defaultconnection") { } public dbset<userprofile> userprofiles { get; set; } public dbset<userwork> userworks { get; set; } }
after page page redirection call savechanges()
instance method of userscontext
, don't see changes made in table data @ all. still see data present in variables defined during page redirection in debug view though.
my current problem this
after user logs in site, check login flag, true, redirect him comment page. flag of user test on true, , login
method becomes
[httppost] [allowanonymous] [validateantiforgerytoken] public actionresult login(loginmodel model, string returnurl) { if (modelstate.isvalid && websecurity.login(model.username, model.password, persistcookie: model.rememberme)) { usercontroller uc = new usercontroller(model.username); if(uc!=null) { if (!uc.flag) { return redirecttoaction("youwereflagged", "account"); } return redirecttolocal(returnurl); } } return view(model); }
and youareflag
method is
[httppost] [authorize] public actionresult youwereflagged(userflagmodel model, string url) { using (usercontroller uc = new usercontroller(user.identity.name)) { uc.comment = model.comment; uc.savechanges(); } return redirecttolocal(url); }
i don't know if should call savechanges
.
Comments
Post a Comment