Esempio n. 1
0
        public static ProductRegRespObj AddProduct(RegProductObj regObj, string username)
        {
            var response = new ProductRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage(),
                },
            };

            try
            {
                var apiResponse = new APIHelper(APIEndpoints.ADD_PRODUCT_ENDPOINT, username, Method.POST).ProcessAPI <RegProductObj, ProductRegRespObj>(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 ActionResult ProductDetail(int clientId, int prodId, string clientName)
        {
            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 RegProductObj()));
                }

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

                if (prodId < 1)
                {
                    ViewBag.SessionError = "Invalid Product Selection";
                    return(View(new RegProductObj()));
                }

                var prodList = Session[$"_myProductList_{clientId}"] as List <ProductObj>;
                if (prodList == null || !prodList.Any())
                {
                    ViewBag.SessionError = "Invalid Product List";
                    return(View(new RegProductObj()));
                }

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

                Session["_curSelectedProductInfo_"] = thisProd;

                var retVal = new RegProductObj
                {
                    ClientId    = clientId,
                    ProductId   = prodId,
                    ClientName  = clientName,
                    Name        = thisProd.Name,
                    Description = thisProd.Description,
                    Status      = thisProd.Status,
                };


                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 RegProductObj()));
            }
        }
        public JsonResult ProcessEditProductRequest(RegProductObj 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["_curSelectedProductInfo_"] as ProductObj;
                if (selProd == null || selProd.ProductId < 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 Product Name" }));
                }



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


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

                var addObj = new EditProductObj
                {
                    AdminUserId = userData.UserId,
                    ClientId    = model.ClientId,
                    Description = model.Description,
                    Name        = model.Name,
                    Status      = model.StatusVal? 1 : 0,
                    ProductId   = model.ProductId,
                };

                var response = ProductService.UpdateProduct(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 ProductSearchObj
                {
                    AdminUserId = userData.UserId,
                    ClientId    = model.ClientId,
                    Status      = -2,
                };

                var retVal = ProductService.LoadProducts(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.Status.IsSuccessful)
                {
                    if (retVal.Products != null && retVal.Products.Any())
                    {
                        Session[$"_myProductList_{model.ClientId}"] = retVal.Products;
                    }
                }

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