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 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"));
            }
        }
 // 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 }));
     }
 }
Esempio n. 4
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"));
            }
        }
Esempio n. 5
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"));
            }
        }
        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));
            }
        }
        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"));
            }
        }
Esempio n. 8
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"));
            }
        }
Esempio n. 9
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"));
     }
 }
 // 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"));
     }
 }
        //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"));
            }
        }
Esempio n. 12
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"));
            }
        }
Esempio n. 13
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"));
            }
        }
Esempio n. 14
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 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"));
            }
        }
Esempio n. 17
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 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"));
            }
        }
        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"));
            }
        }
Esempio n. 20
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"));
            }
        }
Esempio n. 21
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"));
     }
 }
Esempio n. 22
0
        public ActionResult UserEnable(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)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }
                    var aclUser = AclUserContext.GetDetail(dataContext, id);
                    if (aclUser == null)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_FOUND);
                        return(RedirectToAction("Index", "Admin"));
                    }

                    var isSuccess = AclUserContext.Disable(dataContext, aclUser, user.Id, false);
                    if (isSuccess)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, AdminRes.SUCCESS_USER_ENABLE);
                    }
                    else
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, AdminRes.ERROR_USER_ENABLE);
                    }
                    return(RedirectToAction("UserDetail", "Admin", new { id = id }));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AdminController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 23
0
 public ActionResult AdminMenu()
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             if (Request.IsAuthenticated)
             {
                 var userName = User.Identity.Name;
                 var user     = AclUserContext.GetDetail(dataContext, userName);
                 var isAdmin  = user.AccountTypeEx == AccountTypeEnum.Admin;
                 return(PartialView(isAdmin));
             }
             return(PartialView(false));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "AccountController");
         return(PartialView(@"AjaxError", string.Empty));
     }
 }
Esempio n. 24
0
 public ActionResult Index()
 {
     try
     {
         using (var dataContext = new HuntingEntities())
         {
             if (Request.IsAuthenticated)
             {
                 var userName = User.Identity.Name;
                 var user     = AclUserContext.GetDetail(dataContext, userName);
                 var model    = new HomeViewModel(user);
                 return(View(model));
             }
             return(View(new HomeViewModel()));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "HomeController");
         throw;
     }
 }
Esempio n. 25
0
        // GET: UserPoint/Create
        public ActionResult Create(int territoryId)
        {
            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 territory = TerritoryContext.GetDetail(dataContext, territoryId);
                    if (user.CanViewTerritory(territory) == false)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    var model = new UserPointUpdateModel()
                    {
                        IsCreate    = true,
                        TerritoryId = territoryId,
                    };
                    model.FillTerritoryInfo(territory, user);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "UserPointController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 26
0
        // GET: UserUpdate/id
        public ActionResult UserUpdate(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)
                    {
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_NOT_ALLOWED);
                        return(RedirectToAction("Index", "Home"));
                    }

                    AclUserUpdateModel model;
                    if (id.HasValue)
                    {
                        var aclUser = AclUserContext.GetDetail(dataContext, id.Value);
                        model = new AclUserUpdateModel(aclUser);
                    }
                    else
                    {
                        model = new AclUserUpdateModel()
                        {
                            IsCreate = true,
                        };
                    }
                    model.FillCodeLists(languageId);
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "AdminController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 27
0
 // GET: Questionnaire/Create
 public ActionResult Create(int mapItemTypeId)
 {
     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, mapItemTypeId);
             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 }));
             }
             var model = new QuestionnaireUpdateModel()
             {
                 IsCreate      = true,
                 MapItemTypeId = mapItemTypeId,
             };
             return(View(model));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "QuestionnaireController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
 public ActionResult PersonList(TerritoryPersonListModel 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 territory = TerritoryContext.GetDetail(dataContext, model.Id);
             if (user.CanUpdateTerritory(territory) == false)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, GlobalRes.ERROR_NOT_ALLOWED);
                 return(RedirectToAction("Index", "Territory", new { id = model.Id }));
             }
             var result = TerritoryContext.UpdateUserList(dataContext, territory, model);
             if (result == true)
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, TerritoryRes.SUCCESS_UPDATE);
             }
             else
             {
                 ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, TerritoryRes.ERROR_UPDATE);
             }
             return(RedirectToAction("PersonList", "Territory", new { id = model.Id }));
         }
     }
     catch (Exception exception)
     {
         logger.Error(exception, "TerritoryController");
         ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
         return(RedirectToAction("Index", "Home"));
     }
 }
Esempio n. 29
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));
     }
 }
Esempio n. 30
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"));
     }
 }