Пример #1
0
        public ActionResult Create(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 mapItem = MapItemContext.GetDetail(dataContext, model.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"));
                    }

                    if (ModelState.IsValid)
                    {
                        var newItemId = CheckInContext.Update(dataContext, null, model, user, language);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, CheckInRes.SUCCESS_CREATE);
                            return(RedirectToAction("Index", "CheckIn", new { id = model.MapItemId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, CheckInRes.ERROR_CREATE);
                        }
                    }
                    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"));
            }
        }
Пример #2
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());
     }
 }
Пример #3
0
 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());
     }
 }
Пример #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
 public IHttpActionResult CheckinList(int id)
 {
     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, id);
             if (mapItem == null)
             {
                 return(Content(HttpStatusCode.NotFound, NOT_FOUND_MESSAGE));
             }
             if (userSession.AclUser.CanViewTerritory(mapItem.MapItemTypeRecord.Territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             var checkInList = MapItemContext.GetCheckInList(dataContext, mapItem);
             if (checkInList == null)
             {
                 return(Content(HttpStatusCode.InternalServerError, FAILED_MESSAGE));
             }
             var model = checkInList.ConvertAll(item => new CheckInModel(item));
             return(Ok(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }