// assign an application to some user / note in appFVM, personid could = 0! public static void updateAppForActiveAndOwnership(ApplicationPersonIdFlatVM appFVM) { using (DatabaseModel.ErrorModelDbContext db = new DatabaseModel.ErrorModelDbContext()) { db.Database.Initialize(false); var queryDbApp = (from a in db.ApplicationSet where a.ApplicationId == appFVM.ApplicationId select a).First(); queryDbApp.AppName = appFVM.AppName; queryDbApp.IsActive = appFVM.IsActive; // the updated PersonId could be 0, means not related to any user if (appFVM.PersonId > 0) { var queryDbPerson = (from p in db.PersonSet where p.PersonId == appFVM.PersonId select p).FirstOrDefault(); if (queryDbPerson != null) { // only update user's app if he hasn't own it if (false == queryDbApp.Persons.Any(p => p.PersonId == queryDbPerson.PersonId)) { queryDbApp.Persons.Add(queryDbPerson); } } } db.SaveChanges(); } }
public ActionResult EditApp(ApplicationPersonIdFlatVM instance) { if (ModelState.IsValid) { Loader.updateAppForActiveAndOwnership(instance); return(RedirectToAction(WebConstants.VIEW_ALLAPPS_PAGE, WebConstants.HOME_CONTROLLER)); } return(View(instance)); }
// admin role public ActionResult EditApp(int appId) { var appVM = Loader.queryAppByAppId(appId); var appPidFVM = new ApplicationPersonIdFlatVM() { ApplicationId = appVM.ApplicationId, AppName = appVM.AppName, IsActive = appVM.IsActive, PersonId = 0 }; return(View(appPidFVM)); }