// GET: MapItemType/Update/id public ActionResult Update(int id) { 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 mapItemType = MapItemTypeContext.GetDetail(dataContext, id); if (mapItemType == null) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND); return(RedirectToAction("Index", "Home")); } if (user.CanUpdateTerritory(mapItemType.Territory) == false) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED); return(RedirectToAction("Index", "Territory", new { id = mapItemType.TerritoryId })); } var model = new MapItemTypeUpdateModel(mapItemType); return(View(model)); } } catch (Exception exception) { logger.Error(exception, "MapItemTypeController"); ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION); return(RedirectToAction("Index", "Home")); } }
public ActionResult Update(MapItemTypeUpdateModel 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 mapItemType = MapItemTypeContext.GetDetail(dataContext, model.Id); if (mapItemType == null) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND); return(RedirectToAction("Index", "Home")); } if (user.CanUpdateTerritory(mapItemType.Territory) == false) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED); return(RedirectToAction("Index", "Territory", new { id = mapItemType.TerritoryId })); } if (ModelState.IsValid) { var newItemId = MapItemTypeContext.Update(dataContext, mapItemType, model, user); if (newItemId.HasValue) { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, MapItemTypeRes.SUCCESS_UPDATE); return(RedirectToAction("Index", "MapItemType", new { id = model.TerritoryId })); } else { ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, MapItemTypeRes.ERROR_UPDATE); } } return(View(model)); } } catch (Exception exception) { logger.Error(exception, "MapItemTypeController"); ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION); return(RedirectToAction("Index", "Home")); } }
public static int?Update(HuntingEntities dataContext, MapItemType updateItem, MapItemTypeUpdateModel model, AclUser user) { try { if (model.IsCreate) { updateItem = new MapItemType() { SysCreated = DateTime.Now, SysCreator = user.Id, TerritoryId = model.TerritoryId, }; dataContext.MapItemTypes.Add(updateItem); } updateItem.Name = model.Name; updateItem.Description = model.Description; updateItem.SysEditor = user.Id; updateItem.SysUpdated = DateTime.Now; dataContext.SaveChanges(); return(updateItem.Id); } catch (Exception exception) { logger.Error(exception, "Update"); return(null); } }