// 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 IHttpActionResult CreateMapItem(CreateMapItemModel model)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             var session = GetSession();
             if (session == null)
             {
                 return(Content(HttpStatusCode.Unauthorized, SESSION_INVALID_MESSAGE));
             }
             var userSession = AclUserContext.GetUserSession(dataContext, session);
             if (userSession == null)
             {
                 return(Content(HttpStatusCode.Unauthorized, SESSION_INVALID_MESSAGE));
             }
             var territory = TerritoryContext.GetDetail(dataContext, model.TerritoryId);
             if (userSession.AclUser.CanUpdateTerritory(territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             var mapItemType = MapItemTypeContext.GetDetail(dataContext, model.MapItemTypeId);
             if (mapItemType == null || mapItemType.TerritoryId != territory.Id)
             {
                 return(Content(HttpStatusCode.BadRequest, BAD_REQUEST_MESSAGE));
             }
             if (model.IsValid() == false)
             {
                 return(Content(HttpStatusCode.BadRequest, BAD_REQUEST_MESSAGE));
             }
             var pointId = MapItemContext.Create(dataContext, model, userSession.AclUserId);
             if (pointId == null)
             {
                 return(Content(HttpStatusCode.InternalServerError, FAILED_MESSAGE));
             }
             return(Ok(pointId.Value.ToString()));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }