// GET: Territory/UpdateMap
 public ActionResult UpdateMap(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 territory = TerritoryContext.GetDetail(dataContext, id);
             if (user.CanUpdateTerritory(territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new TerritoryDetailModel(territory, user);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "TerritoryController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
Example #2
0
 // GET: Admin
 public ActionResult Index(AclUserFilter filter, int?page)
 {
     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.AccountTypeEx != AccountTypeEnum.Admin)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             filter.PrepareFilter(languageId);
             int pageIndex     = page ?? 0;
             var itemList      = AclUserContext.GetList(dataContext, filter, pageIndex);
             var itemListModel = new AclUserListModel(itemList, pageIndex);
             var model         = new AclUserPageModel(itemListModel, filter);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AdminController");
         return(RedirectToAction("Index", "Home"));
     }
 }
        public ActionResult ContactAction(int id, bool accept)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        return(Content("NOT_ALLOWED"));
                    }
                    var contact = TerritoryContext.GetTerritoryUserContact(dataContext, id);
                    if (contact == null)
                    {
                        return(Content("NOT_FOUND"));
                    }
                    if (contact.Territory.StewardId != user.Id)
                    {
                        return(Content("NOT_ALLOWED"));
                    }

                    var result = TerritoryContext.ContactAction(dataContext, contact, accept, user);
                    if (result == true)
                    {
                        return(Content("OK"));
                    }
                    return(Content("ERROR"));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                return(Content("ERROR"));
            }
        }
 public IHttpActionResult TerritoryList()
 {
     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 territoryList = TerritoryContext.GetListForUser(dataContext, userSession.AclUser);
             var model         = new TerritoryListModel(territoryList, userSession.AclUser);
             return(Ok(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }
 // GET: Territory/PersonList/id
 public ActionResult PersonList(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 territory = TerritoryContext.GetDetail(dataContext, id);
             if (user.CanUpdateTerritory(territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Territory", new { id = id }));
             }
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             var model      = new TerritoryPersonListModel(territory, languageId);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "TerritoryController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Territory", new { id = id }));
     }
 }
        public ActionResult InviteUser(int id, string email, string name)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    var user = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (user == null)
                    {
                        return(Content("ERROR"));
                    }
                    var territory = TerritoryContext.GetDetail(dataContext, id);
                    if (user.CanUpdateTerritory(territory) == false)
                    {
                        return(Content("ERROR"));
                    }

                    var result = TerritoryContext.InviteUser(dataContext, territory, email, name, user);
                    if (result == true)
                    {
                        return(Content("OK"));
                    }
                    return(Content("CREATE"));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                return(Content("ERROR"));
            }
        }
        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));
            }
        }
Example #8
0
 public ActionResult DemoLogin(string returnUrl)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             UserSession userSession;
             var         demoUser = dataContext.AclUsers.FirstOrDefault(item => item.IsDeleted == false && item.AccountType == (int)AccountTypeEnum.Demo);
             var         result   = AclUserContext.LoginDemoUser(dataContext, demoUser, out userSession);
             if (result)
             {
                 FormsAuthentication.SetAuthCookie(userSession.AclUser.Email, false);
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.SUCCESS_LOGIN_DEMO);
                 return(RedirectToLocal(returnUrl));
             }
             ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_LOGIN_DEMO);
             return(RedirectToAction("Login", "Account"));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         return(RedirectToAction("Index", "Home"));
     }
 }
Example #9
0
 public ActionResult ForgottenPasswordConfirm(string code)
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
             if (string.IsNullOrWhiteSpace(User.Identity.Name) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Home"));
             }
             var aclUser = AclUserContext.GetDetailByEmailCode(dataContext, code);
             if (aclUser == null)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_CODE_INVALID);
                 return(RedirectToAction("Index", "Home"));
             }
             if (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                 return(RedirectToAction("Index", "Home"));
             }
             var model = new ChangePasswordModel(aclUser);
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
 public IHttpActionResult TerritoryDetail(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 territory = TerritoryContext.GetDetail(dataContext, id);
             if (userSession.AclUser.CanViewTerritory(territory) == false)
             {
                 return(Content(HttpStatusCode.Forbidden, FORBIDDEN_MESSAGE));
             }
             var model = new TerritoryDetailModel(territory, userSession.AclUser);
             return(Ok(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }
 public IHttpActionResult UserLocation(UserLocationParamModel 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 locationId = UserLocationContext.CreateUserLocation(dataContext, model.TrackId, model.LocationX, model.LocationY, userSession.AclUserId);
             if (locationId == null)
             {
                 return(Content(HttpStatusCode.InternalServerError, FAILED_MESSAGE));
             }
             return(Ok());
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "MobileController");
         return(InternalServerError());
     }
 }
Example #12
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var aclUser    = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        var isSuccess = AclUserContext.ChangePassword(dataContext, aclUser, model, false);
                        if (isSuccess)
                        {
                            FormsAuthentication.SetAuthCookie(aclUser.Email, false);
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_PASSWORD_CHANGED);
                            return(RedirectToAction("Manage", "Account"));
                        }
                    }
                    model = new ChangePasswordModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #13
0
        public ActionResult ChangePassword()
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    var aclUser    = AclUserContext.GetDetail(dataContext, User.Identity.Name);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var model = new ChangePasswordModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #14
0
 public void ProcessJob()
 {
     using (var dataContext = new HuntingEntities())
     {
         AclUserContext.ClearExpiredEmailCodes(dataContext);
     }
 }
        public ActionResult SaveMapAjax(int id, string mapData)
        {
            var model = new TerritoryMapSavedModel();

            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(PartialView(model));
                    }
                    var territory = TerritoryContext.GetDetail(dataContext, id);
                    if (user.CanUpdateTerritory(territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(PartialView(model));
                    }

                    var saveModel = JsonConvert.DeserializeObject <MapSaveDataModel>(mapData);
                    model = TerritoryContext.SaveMap(dataContext, id, saveModel, user.Id);
                    return(PartialView(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(PartialView(model));
            }
        }
        public IHttpActionResult Login(LoginModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    UserSession userSession;
                    var         result = AclUserContext.LoginUser(dataContext, model.Email, model.Password, out userSession);
                    switch (result)
                    {
                    case LoginResultEnum.Error:
                        return(InternalServerError());

                    case LoginResultEnum.NotFound:
                        return(NotFound());

                    case LoginResultEnum.WrongPassword:
                        return(NotFound());

                    case LoginResultEnum.NotAllowed:
                        return(NotFound());

                    case LoginResultEnum.Success:
                        var responseModel = new LoginResponseModel(userSession);
                        return(Ok(responseModel));
                    }
                    return(NotFound());
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "MobileController - Login, Model = {0}", (model != null ? model.Email : "N/A"));
                return(InternalServerError());
            }
        }
Example #17
0
        // GET: UserDetail/id
        public ActionResult UserDetail(int id)
        {
            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.AccountTypeEx != AccountTypeEnum.Admin)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    var aclUser = AclUserContext.GetDetail(dataContext, id);
                    var model   = new AclUserDetailModel(aclUser);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AdminController");
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #18
0
 public void ProcessJob()
 {
     using (var dataContext = new HuntingEntities())
     {
         var systemAccount = AclUserContext.GetAdminAccount(dataContext);
         TerritoryContext.RefreshDemoAccount(dataContext, systemAccount);
     }
 }
Example #19
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            LanguageContext.CreateLanguages();
            AclUserContext.CreateAdmin();
        }
        //POST: Territory/Contact
        public ActionResult Contact(int id, string message)
        {
            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 territory = TerritoryContext.GetDetail(dataContext, id);
                    if (territory == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.StewardId == user.Id)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.TerritoryUsers.Any(item => item.AclUserId == user.Id))
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }
                    if (territory.TerritoryUserContacts.Any(item => item.IsDeleted == false && item.AclUserId == user.Id))
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("List", "Territory"));
                    }

                    var result = TerritoryContext.Contact(dataContext, territory, user, message);
                    if (result)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, TerritoryRes.SUCCESS_CONTACT);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, TerritoryRes.ERROR_CONTACT);
                    }
                    return(RedirectToAction("List", "Territory"));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                return(RedirectToAction("List", "Territory"));
            }
        }
Example #21
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"));
            }
        }
Example #22
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"));
            }
        }
Example #23
0
        public ActionResult UserUpdate(AclUserUpdateModel 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.AccountTypeEx != AccountTypeEnum.Admin)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    AclUser updateItem = null;
                    if (model.IsCreate == false)
                    {
                        updateItem = AclUserContext.GetDetail(dataContext, model.Id);
                        if (updateItem == null)
                        {
                            return(RedirectToAction("Index", "Admin"));
                        }
                    }
                    else
                    {
                        var isUsed = AclUserContext.IsEmailUsed(dataContext, model.Email, model.Id);
                        if (isUsed)
                        {
                            ModelState.AddModelError("Email", AdminRes.VALIDATION_EMAIL_USED);
                        }
                    }
                    if (ModelState.IsValid)
                    {
                        var itemId = AclUserContext.Update(dataContext, updateItem, model, user.Id);
                        if (itemId.HasValue)
                        {
                            return(RedirectToAction("UserDetail", "Admin", new { id = itemId.Value }));
                        }
                        ModelState.AddModelError("", GlobalRes.VALIDATION_UPDATE_FAILED);
                    }
                    model.FillCodeLists(languageId);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AdminController");
                return(RedirectToAction("Index", "Home"));
            }
        }
 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"));
            }
        }
        public ActionResult Update(MapItemTypeUpdateModel 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 mapItemType = MapItemTypeContext.GetDetail(dataContext, model.Id);
                    if (mapItemType == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(mapItemType.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Territory", new { id = mapItemType.TerritoryId }));
                    }

                    if (ModelState.IsValid)
                    {
                        var newItemId = MapItemTypeContext.Update(dataContext, mapItemType, model, user);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, MapItemTypeRes.SUCCESS_UPDATE);
                            return(RedirectToAction("Index", "MapItemType", new { id = model.TerritoryId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, MapItemTypeRes.ERROR_UPDATE);
                        }
                    }
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "MapItemTypeController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #27
0
        public ActionResult ForgottenPassword(ForgotPasswordModel model)
        {
            try
            {
                using (var dataContext = new HuntingEntities())
                {
                    int languageId = (int)Session[LocalizationAttribute.SESSION_LANGUAGE_ID];
                    if (string.IsNullOrWhiteSpace(User.Identity.Name) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        var aclUser = AclUserContext.GetDetail(dataContext, model.Email);
                        if (aclUser != null)
                        {
                            if (aclUser.AccountTypeEx == AccountTypeEnum.Admin)
                            {
                                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AccountRes.ERROR_FORGOTTEN_PASSWORD_ADMIN);
                                return(RedirectToAction("Index", "Home"));
                            }
                            var isSuccess = AclUserContext.ForgotPassword(dataContext, aclUser);
                            if (isSuccess)
                            {
                                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_FORGOTTEN_PASSWORD);
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AccountRes.SUCCESS_FORGOTTEN_PASSWORD);
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AccountController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
 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());
     }
 }
        public ActionResult DeleteUser(int territoryId, 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 territory = TerritoryContext.GetDetail(dataContext, territoryId);
                    if (territory == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Territory", new { id = territoryId }));
                    }

                    var isSuccess = TerritoryContext.DeleteUser(dataContext, territory, id, user);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, TerritoryRes.SUCCESS_DELETE_USER);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, TerritoryRes.ERROR_DELETE_USER);
                    }
                    return(RedirectToAction("PersonList", "Territory", new { id = territoryId }));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "TerritoryController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Delete(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 question = QuestionContext.GetDetail(dataContext, id);
                    if (question == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (user.CanUpdateTerritory(question.Questionnaire.MapItemType.Territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Territory", new { id = question.Questionnaire.MapItemType.TerritoryId }));
                    }

                    var isSuccess = QuestionContext.Delete(dataContext, question, user);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, QuestionRes.SUCCESS_DELETE);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, QuestionRes.ERROR_DELETE);
                    }
                    return(RedirectToAction("Index", "Question", new { id = question.QuestionnaireId }));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "QuestionController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }