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 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());
     }
 }
 // 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 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));
            }
        }
 // 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"));
            }
        }
        public ActionResult Create(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 territory = TerritoryContext.GetDetail(dataContext, model.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 = model.TerritoryId }));
                    }

                    if (ModelState.IsValid)
                    {
                        var newItemId = MapItemTypeContext.Update(dataContext, null, model, user);
                        if (newItemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, MapItemTypeRes.SUCCESS_CREATE);
                            return(RedirectToAction("Index", "MapItemType", new { id = model.TerritoryId }));
                        }
                        else
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, MapItemTypeRes.ERROR_CREATE);
                        }
                    }
                    return(View(model));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "MapItemTypeController");
                ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Danger, GlobalRes.ERROR_EXCEPTION);
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #8
0
        public ActionResult Create(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 territory = TerritoryContext.GetDetail(dataContext, model.TerritoryId);
                    if (user.CanViewTerritory(territory) == 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, null, model, user.Id);
                        if (itemId.HasValue)
                        {
                            ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Success, UserPointRes.SUCCESS_CREATE);
                            return(RedirectToAction("Index", "Territory", new { id = model.TerritoryId }));
                        }
                        ContextUtils.CreateActionStateCookie(Response, ActionTypeEnum.Warning, UserPointRes.ERROR_CREATE);
                    }

                    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"));
            }
        }
 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"));
            }
        }
Example #11
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"));
            }
        }
 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"));
     }
 }