Пример #1
0
        public ActionResult Update(UserPointUpdateModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var userName   = User.Identity.Name;

                    var user = AclUserContext.GetDetail(dataContext, userName);
                    if (user == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var userPoint = UserPointContext.GetUserPoint(dataContext, model.Id);
                    if (userPoint == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateUserPoint(userPoint) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    model.Validate(ModelState);
                    if (ModelState.IsValid)
                    {
                        var itemId = UserPointContext.Update(dataContext, userPoint, model, user.Id);
                        if (itemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, UserPointRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "Territory", new { id = model.TerritoryId }));
                        }
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, UserPointRes.ERROR_UPDATE);
                    }

                    model.FillTerritoryInfo(userPoint.Territory, user);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "UserPointController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #2
0
 public IHttpActionResult CreateUserPoint(CreateUserPointModel 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.CanViewTerritory(territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             if (model.IsValid() == false)
             {
                 return(Content(HttpStatusCode.BadRequest, BAD_REQUEST_MESSAGE));
             }
             var updateModel = new UserPointUpdateModel(model);
             var pointId     = UserPointContext.Update(dataContext, null, updateModel, 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());
     }
 }