コード例 #1
0
        public ActionResult Update(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)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var checkIn = CheckInContext.GetDetail(dataContext, model.Id);
                    if (checkIn == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(checkIn.MapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "CheckIn", new { id = checkIn.MapItemId }));
                    }

                    CheckInContext.Validate(dataContext, model, ModelState);
                    if (ModelState.IsValid)
                    {
                        var newItemId = CheckInContext.Update(dataContext, checkIn, model, user, language);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, CheckInRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "CheckIn", new { id = model.MapItemId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, CheckInRes.ERROR_UPDATE);
                        }
                    }
                    model.FillCodeLists(dataContext, checkIn.MapItem);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #2
0
        public ActionResult ScriptDefine()
        {
            int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
            var language   = LanguageContext.GetLanguage(languageId);
            var model      = new ScriptDefineModel()
            {
                IsDebug    = true,
                Lang       = language.Shortcut,
                Locale     = language.Code,
                DateFormat = language.DateFormatJS,
                TimeFormat = language.TimeFormatJS,
                MapAPIKey  = Settings.Default.GoogleMapsAPIKey,
            };

            return(PartialView(model));
        }
コード例 #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string   code     = null;
            Language language = null;

            if (filterContext.RouteData.Values["lang"] != null &&
                string.IsNullOrWhiteSpace(filterContext.RouteData.Values["lang"].ToString()) == false)
            {
                // set the culture from the route data (url)
                code     = filterContext.RouteData.Values["lang"].ToString();
                language = LanguageContext.GetLanguage(code);
                SetLocale(filterContext, language.Code, true);
            }
            else
            {
                // load the culture info from the cookie
                var cookie = filterContext.HttpContext.Request.Cookies[COOKIE_LANGUAGE];
                if (cookie != null)
                {
                    // set the culture by the cookie content
                    code = cookie.Value;
                }
                else
                {
                    var languages = filterContext.HttpContext.Request.UserLanguages;
                    if (languages != null && languages.Length > 0)
                    {
                        // set the culture by the location if not specified
                        code = filterContext.HttpContext.Request.UserLanguages[0];
                    }
                }
                language = LanguageContext.GetLanguage(code);
                SetLocale(filterContext, language.Code, false);
            }
            HttpContext.Current.Session[SESSION_LANGUAGE_ID] = language.Id;
            filterContext.Controller.ViewBag.LangShort       = language.Shortcut;

            // save the location into cookie
            HttpCookie saveCookie = new HttpCookie(COOKIE_LANGUAGE, Thread.CurrentThread.CurrentUICulture.Name);

            saveCookie.Expires = DateTime.Now.AddYears(1);
            filterContext.HttpContext.Response.SetCookie(saveCookie);

            base.OnActionExecuting(filterContext);
        }
コード例 #4
0
        // GET: CheckIn/id
        public ActionResult Index(int id, CheckInFilter filter, int?page)
        {
            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)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var mapItem = MapItemContext.GetDetail(dataContext, id);
                    if (mapItem == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanViewTerritory(mapItem.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    filter.PrepareFilter();
                    filter.MapItemId = mapItem.Id;
                    int pageIndex     = page ?? 0;
                    var itemList      = CheckInContext.GetList(dataContext, filter, pageIndex);
                    var itemListModel = new CheckInListModel(itemList, pageIndex, language);
                    var model         = new CheckInPageModel(itemListModel, filter, mapItem);
                    model.CanUpdate = user.CanUpdateTerritory(mapItem.Territory);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "CheckInController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #5
0
 // GET: CheckIn/Create
 public ActionResult Create(int mapItemId)
 {
     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)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var mapItem = MapItemContext.GetDetail(dataContext, mapItemId);
             if (mapItem == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                 return(RedirectToAction("Index", "Home"));
             }
             if (user.CanViewTerritory(mapItem.Territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new CheckInUpdateModel()
             {
                 IsCreate  = true,
                 MapItemId = mapItemId,
                 CheckTime = ContextUtils.FormatDateTime(DateTime.Now, language, true),
             };
             model.FillCodeLists(dataContext, mapItem);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "CheckInController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
コード例 #6
0
 // GET: CheckIn/Detail/id
 public ActionResult Detail(int id)
 {
     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)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var checkIn = CheckInContext.GetDetail(dataContext, id);
             if (checkIn == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                 return(RedirectToAction("Index", "Home"));
             }
             if (user.CanViewTerritory(checkIn.MapItem.Territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new CheckInDetailModel(checkIn, language);
             model.CanUpdate = user.CanUpdateTerritory(checkIn.MapItem.Territory);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "CheckInController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
コード例 #7
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));
     }
 }