public ActionResult OptionTableAjax(QuestionUpdateModel model, string formAction, int?index)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_ALLOWED));
                    }
                    var questionnaire = QuestionnaireContext.GetDetail(dataContext, model.QuestionnaireId);
                    if (questionnaire == null)
                    {
                        return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_FOUND));
                    }
                    if (user.CanUpdateTerritory(questionnaire.MapItemType.Territory) == false)
                    {
                        return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_ALLOWED));
                    }

                    QuestionContext.OptionTableAction(dataContext, model, formAction, index);
                    ModelState.Clear();
                    return(PartialView("~/Views/Question/CommonLayout/OptionList.cshtml", model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "QuestionController");
                return(PartialView(@"AjaxError", GlobalRes.ERROR_EXCEPTION));
            }
        }
Ejemplo n.º 2
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"));
     }
 }
Ejemplo n.º 3
0
 public IHttpActionResult CheckIn(CreateCheckInModel 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 mapItem = MapItemContext.GetDetail(dataContext, model.MapItemId);
             if (mapItem == null)
             {
                 return(Content(HttpStatusCode.NotFound, NOT_FOUND_MESSAGE));
             }
             if (userSession.AclUser.CanViewTerritory(mapItem.Territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             Questionnaire questionnaire = null;
             if (model.QuestionnaireId.HasValue)
             {
                 questionnaire = QuestionnaireContext.GetDetail(dataContext, model.QuestionnaireId.Value);
             }
             if (model.IsValid(dataContext, questionnaire) == false)
             {
                 return(Content(HttpStatusCode.BadRequest, BAD_REQUEST_MESSAGE));
             }
             var updateModel = new CheckInUpdateModel(model, questionnaire);
             var pointId     = CheckInContext.Update(dataContext, null, updateModel, userSession.AclUser, null);
             if (pointId == null)
             {
                 return(Content(HttpStatusCode.InternalServerError, FAILED_MESSAGE));
             }
             return(Ok(pointId.Value.ToString()));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }
        public ActionResult Create(QuestionUpdateModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    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.QuestionnaireId);
                    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 = QuestionContext.Update(dataContext, null, model, user);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, QuestionRes.SUCCESS_CREATE);
                            return(RedirectToAction("Index", "Question", new { id = model.QuestionnaireId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, QuestionRes.ERROR_CREATE);
                        }
                    }
                    model.FillCodeList(languageId);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "QuestionController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 5
0
 public ActionResult SelectQuestionnaireAjax(CheckInUpdateModel model)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             var language   = LanguageContext.GetLanguage(languageId);
             var user       = AclUserContext.GetDetail(dataContext, User.Identity.Name);
             if (user == null)
             {
                 return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_ALLOWED));
             }
             ModelState.Clear();
             if (model.QuestionnaireId.HasValue)
             {
                 var questionnaire = QuestionnaireContext.GetDetail(dataContext, model.QuestionnaireId.Value);
                 if (questionnaire == null)
                 {
                     return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_FOUND));
                 }
                 if (user.CanViewTerritory(questionnaire.MapItemType.Territory) == false)
                 {
                     return(PartialView(@"AjaxError", GlobalRes.ERROR_NOT_ALLOWED));
                 }
                 model.FillQuestionnaire(null, questionnaire, language);
                 model.FillCodeLists(dataContext, null);
             }
             return(PartialView(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "CheckInController");
         return(PartialView(@"AjaxError", GlobalRes.ERROR_EXCEPTION));
     }
 }