public static AlertItemRegRespObj AddAlertItem(RegAlertItemObj regObj, string username) { var response = new AlertItemRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage(), }, }; try { var apiResponse = new APIHelper(APIEndpoints.ADD_ALERT_ITEM_ENDPOINT, username, Method.POST).ProcessAPI <RegAlertItemObj, AlertItemRegRespObj>(regObj, out var msg); if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message)) { return(apiResponse); } response.Status.Message.FriendlyMessage = msg.Message; response.Status.Message.TechnicalMessage = msg.TechMessage; return(response); } catch (Exception ex) { UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; return(response); } }
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" })); } }