public ActionResult PersonList(TerritoryPersonListModel model) { try { using (var dataContext = new HuntingEntities()) { var user = AclUserContext.GetDetail(dataContext, User.Identity.Name); if (user == null) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED); return(RedirectToAction("Index", "Home")); } var territory = TerritoryContext.GetDetail(dataContext, model.Id); if (user.CanUpdateTerritory(territory) == false) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED); return(RedirectToAction("Index", "Territory", new { id = model.Id })); } var result = TerritoryContext.UpdateUserList(dataContext, territory, model); if (result == true) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, TerritoryRes.SUCCESS_UPDATE); } else { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, TerritoryRes.ERROR_UPDATE); } return(RedirectToAction("PersonList", "Territory", new { id = model.Id })); } } catch (Exception exception) { logger.Error(exception, "TerritoryController"); ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION); return(RedirectToAction("Index", "Home")); } }
public static bool UpdateUserList(HuntingEntities dataContext, Territory territory, TerritoryPersonListModel model) { try { foreach (var modelUser in model.UserList) { var user = territory.TerritoryUsers.FirstOrDefault(item => item.Id == modelUser.Id); if (user != null) { user.UserRoleEx = modelUser.Role; } } dataContext.SaveChanges(); return(true); } catch (Exception exception) { logger.Error(exception, "UpdatePersonList"); return(false); } }