public static ProductItemRegRespObj UpdateProductItem(EditProductItemObj regObj, string username) { var response = new ProductItemRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage(), }, }; try { var apiResponse = new APIHelper(APIEndpoints.UPDATE_PRODUCT_ITEM_ENDPOINT, username, Method.POST).ProcessAPI <EditProductItemObj, ProductItemRegRespObj>(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 ProcessEditProductRequest(RegProductItemObj 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 selProd = Session["_curSelectedProductItemInfo_"] as ProductItemObj; if (selProd == null || selProd.ProductId < 1 || selProd.ProductItemId < 1) { return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = true })); } if (model == null) { return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = true })); } if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 2) { return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Product Item Name" })); } if (string.IsNullOrEmpty(model.Title) || model.Title.Length < 2) { return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Product Item Title" })); } if (model.ClientId < 1) { return(Json(new { IsSuccessful = false, Error = "Invalid Client Information", IsAuthenticated = true, IsReload = false, })); } if (model.ProductId < 1) { return(Json(new { IsSuccessful = false, Error = "Invalid Product Information", IsAuthenticated = true, IsReload = false, })); } if (model.CurrentImplementation < 1 || model.CurrentImplementation > 2) { return(Json(new { IsSuccessful = false, Error = "Invalid Current Implementation", IsAuthenticated = true, IsReload = false, })); } if (string.IsNullOrEmpty(model.LiveAPIUrl) || model.LiveAPIUrl.Length < 2) { return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Live URL" })); } if (string.IsNullOrEmpty(model.SandBoxAPIUrl) || model.SandBoxAPIUrl.Length < 2) { return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Sand-Box URL" })); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length < 2) { return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Product Item Description" })); } var addObj = new EditProductItemObj { AdminUserId = userData.UserId, ClientId = model.ClientId, CurrentImplementation = model.CurrentImplementation, Description = model.Description, DisplayDemographicStat = model.DisplayDemographicStat, DisplayLocationStat = model.DisplayLocationStat, DisplaySummaryStat = model.DisplaySummaryStat, HasOtherStat = model.HasOtherStat, LiveAPIUrl = model.LiveAPIUrl, Name = model.Name, SandBoxAPIUrl = model.SandBoxAPIUrl, Status = 1, Title = model.Title, ProductId = model.ProductId, ProductItemId = model.ProductItemId, }; var response = ProductItemService.UpdateProductItem(addObj, 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 })); } var searchObj = new ProductItemSearchObj { AdminUserId = userData.UserId, ClientId = model.ClientId, ProductId = model.ProductId, Status = -2, }; var retVal = ProductItemService.LoadProductItems(searchObj, userData.Username); if (retVal?.Status != null && retVal.Status.IsSuccessful) { if (retVal.ProductItems != null && retVal.ProductItems.Any()) { Session[$"_myProductItemList_{model.ProductId}"] = retVal.ProductItems; } } 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" })); } }