Ejemplo n.º 1
0
        public JsonResult ProcessAddAlertItemRequest(RegAlertItemObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid SMS Route Name" }));
                }

                if (string.IsNullOrEmpty(model.ShortName) || model.ShortName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Alert Short Name" }));
                }

                model.AdminUserId = userData.UserId;
                model.Status      = model.StatusVal ? 1 : 0;

                if (Session["_AlertItemList_"] is List <AlertItemObj> previousAlertItemList)
                {
                    if (previousAlertItemList.Count(x => x.Name.ToLower().Trim().ToStandardHash() == model.Name.ToLower().Trim().ToStandardHash()) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Alert Item Information  Already Exist!" }));
                    }
                }


                var response = AlertItemService.AddAlertItem(model, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add nomination Source" : response.Status.Message.TechnicalMessage }));
                }

                Session["_AlertItemList_"] = null;
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <AlertItemObj>()));
                }

                if (Session["_AlertItemList_"] is List <AlertItemObj> mylist && mylist.Any())
                {
                    return(View(mylist));
                }

                var searchObj = new AlertItemSearchObj
                {
                    AdminUserId = userData.UserId,
                    AlertItemId = 0,
                    Status      = 0
                };

                var retVal = AlertItemService.LoadAlertItems(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = "AlertItem list is empty!";
                    return(View(new List <AlertItemObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? " AlertItem list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <AlertItemObj>()));
                }
                if (retVal.AlertItems == null || !retVal.AlertItems.Any())
                {
                    ViewBag.Error = "AlertItem list is empty!";
                    return(View(new List <AlertItemObj>()));
                }

                //Order By AlertItem Name
                var AlertItems = retVal.AlertItems.OrderBy(m => m.Name).ToList();
                Session["_AlertItemList_"] = AlertItems;
                return(View(AlertItems));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <AlertItemObj>()));
            }
        }
Ejemplo n.º 3
0
        public JsonResult ProcessDeleteRequest(int id)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (id < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Invalid / Empty Selection" }));
                }
                var previousAlertItemList = Session["_AlertItemList_"] as List <AlertItemObj>;
                if (previousAlertItemList == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = true }));
                }

                var thisItem = previousAlertItemList.Find(m => m.AlertItemId == id);
                if (thisItem == null || thisItem.AlertItemId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Selected item does not exist in the collection" }));
                }

                var passObj = new DeleteAlertItemObj
                {
                    AdminUserId = userData.UserId,
                    AlertItemId = id
                };

                var response = AlertItemService.DeleteAlertItem(passObj, User.Identity.Name);
                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = response.Status.Message.FriendlyMessage }));
                }

                Session["_AlertItemList_"] = null;
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Ejemplo n.º 4
0
        public JsonResult ProcessEditAlertItemRequest(AlertItemObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                var selAlertItem = Session["_CurrentSelAlertItem_"] as AlertItemObj;
                if (selAlertItem == null || selAlertItem.AlertItemId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.AlertItemId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Selection" }));
                }

                if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid AlertItem Name" }));
                }

                if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid AlertItem Name" }));
                }

                var passObj = new EditAlertItemObj
                {
                    AdminUserId = userData.UserId,
                    Name        = model.Name,
                    AlertItemId = selAlertItem.AlertItemId,
                    ShortName   = model.ShortName,
                    Status      = model.StatusVal ? 1 : 0,
                };

                if (!GenericVal.Validate(model, out var msg))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = $"Validation Error Occurred! Detail: {msg}" }));
                }

                var response = AlertItemService.UpdateAlertItem(passObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add course of study" : response.Status.Message.TechnicalMessage }));
                }

                Session["_CurrentSelAlertItem_"] = null;
                Session["_AlertItemList_"]       = null;
                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }