Exemple #1
0
 // GET: Questionnaire/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 questionnaire = QuestionnaireContext.GetDetail(dataContext, id);
             if (questionnaire == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                 return(RedirectToAction("Index", "Home"));
             }
             if (user.CanUpdateTerritory(questionnaire.MapItemType.Territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Territory", new { id = questionnaire.MapItemType.TerritoryId }));
             }
             var model = new QuestionnaireUpdateModel(questionnaire);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "QuestionnaireController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemple #2
0
        public ActionResult Update(QuestionnaireUpdateModel 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 questionnaire = QuestionnaireContext.GetDetail(dataContext, model.Id);
                    if (questionnaire == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(questionnaire.MapItemType.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Territory", new { id = questionnaire.MapItemType.TerritoryId }));
                    }

                    if (ModelState.IsValid)
                    {
                        var newItemId = QuestionnaireContext.Update(dataContext, questionnaire, model, user);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, QuestionnaireRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "Questionnaire", new { id = model.MapItemTypeId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, QuestionnaireRes.ERROR_UPDATE);
                        }
                    }
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "QuestionnaireController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
        public static int?Update(HuntingEntities dataContext, Questionnaire updateItem, QuestionnaireUpdateModel model, AclUser user)
        {
            try
            {
                if (model.IsCreate)
                {
                    updateItem = new Questionnaire()
                    {
                        SysCreated    = DateTime.Now,
                        SysCreator    = user.Id,
                        MapItemTypeId = model.MapItemTypeId,
                    };
                    dataContext.Questionnaires.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);
            }
        }