public static ProductItemRegRespObj AddProductItem(RegProductItemObj regObj, string username)
        {
            var response = new ProductItemRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.ADD_PRODUCT_ITEM_ENDPOINT, username, Method.POST).ProcessAPI <RegProductItemObj, 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" }));
            }
        }
        public ActionResult EditProduct(int clientId, int productId, int itemId, string clientName, string productName)
        {
            try
            {
                ViewBag.Error        = "";
                ViewBag.SessionError = "";
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    ViewBag.SessionError = "Your session has expired! Please re-login";
                    return(View(new RegProductItemObj()));
                }

                if (clientId < 1 || clientName.IsNullOrEmpty() || clientName.Length < 2)
                {
                    ViewBag.SessionError = "Invalid Client Selection";
                    return(View(new RegProductItemObj()));
                }

                if (productId < 1 || productName.IsNullOrEmpty() || productName.Length < 2)
                {
                    ViewBag.SessionError = "Invalid Product Selection";
                    return(View(new RegProductItemObj()));
                }

                if (itemId < 1)
                {
                    ViewBag.SessionError = "Invalid Product Item Selection";
                    return(View(new RegProductItemObj()));
                }

                var prodList = Session[$"_myProductItemList_{productId}"] as List <ProductItemObj>;
                if (prodList == null || !prodList.Any())
                {
                    ViewBag.SessionError = "Invalid Product List";
                    return(View(new RegProductItemObj()));
                }

                var thisProd = prodList.Find(m => m.ProductId == productId && m.ClientId == clientId && m.ProductItemId == itemId);
                if (thisProd == null || thisProd.ProductId < 1)
                {
                    ViewBag.SessionError = "Invalid Product Information";
                    return(View(new RegProductItemObj()));
                }

                Session["_curSelectedProductItemInfo_"] = thisProd;

                var retVal = new RegProductItemObj
                {
                    ClientId               = thisProd.ClientId,
                    ProductId              = thisProd.ProductId,
                    ClientName             = clientName,
                    CurrentImplementation  = thisProd.CurrentImplementation,
                    Description            = thisProd.Description,
                    DisplayDemographicStat = thisProd.DisplayDemographicStat,
                    DisplayLocationStat    = thisProd.DisplayLocationStat,
                    DisplaySummaryStat     = thisProd.DisplaySummaryStat,
                    HasOtherStat           = thisProd.HasOtherStat,
                    LiveAPIUrl             = thisProd.LiveAPIUrl,
                    Name          = thisProd.Name,
                    SandBoxAPIUrl = thisProd.SandBoxAPIUrl,
                    Title         = thisProd.Title,
                    ProductName   = productName,
                    AdminUserId   = 1,
                    Status        = thisProd.Status,
                    ProductItemId = thisProd.ProductItemId,
                };


                return(View(retVal));
            }
            catch (Exception ex)
            {
                ViewBag.SessionError = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new RegProductItemObj()));
            }
        }