public static dbentities.ProductLog DtoToEntity(this ProductLogDetailRequest request)
        {
            dbentities.ProductLog entity = null;

            if (request != null)
            {
                entity = new dbentities.ProductLog
                {
                    ProductID          = request.ProductId,
                    ProductLogsID      = request.ProductLogsId,
                    ProductCode        = request.ProductCode,
                    CreatedBy          = request.CreatedBy,
                    CreatedTime        = request.CreatedTime,
                    ProductDescription = request.ProductDescription,
                    Quantity           = request.Quantity,
                    IsActive           = request.IsActive,
                    CategoryID         = request.CategoryId,
                };
            }

            return(entity);
        }
Exemple #2
0
        public JsonResult UpdateProductDetails(ProductDetailRequest request)
        {
            bool   isSucess            = false;
            string messageAlert        = string.Empty;
            bool   productUpdateResult = false;

            var currentUserId       = Session[LookupKey.SessionVariables.UserId].IsNull() ? 0 : Convert.ToInt64(Session[LookupKey.SessionVariables.UserId]);
            var passedProductResult = _productServices.GetAll().Where(m => m.ProductId == request.ProductId).FirstOrDefault();

            request.CreatedTime  = passedProductResult.CreatedTime;
            request.ModifiedBy   = currentUserId;
            request.ModifiedTime = DateTime.Now;



            //if (ModelState.IsValid)
            //{
            var codeProductDetailResult = _productServices.GetAll().Where(p => p.ProductCode == request.ProductCode &&
                                                                          p.IsActive &&
                                                                          p.ProductId != request.ProductId).FirstOrDefault();

            #region Validate same product code
            if (!codeProductDetailResult.IsNull())
            {
                return(Json(new { isSucess = isSucess, messageAlert = Messages.ProductCodeValidation }, JsonRequestBehavior.AllowGet));
            }
            #endregion


            //Update Product Details
            productUpdateResult = _productServices.UpdateDetails(request);

            if (!productUpdateResult)
            {
                return(Json(new { isSucess = isSucess, messageAlert = Messages.ServerError }, JsonRequestBehavior.AllowGet));
            }

            #region Product Price
            for (int i = 1; i <= 3; i++)
            {
                var price = 0.0m;
                switch (i)
                {
                case 1:
                    price = request.BigBuyerPrice;
                    break;

                case 2:
                    price = request.ResellerPrice;
                    break;

                case 3:
                    price = request.RetailerPrice;
                    break;

                default:
                    price = 0;
                    break;
                }
                var productPricesResult = _productServices.GetAllProductPrices().Where(m => m.ProductId == request.ProductId && m.PriceTypeId == i).FirstOrDefault();
                if (!productPricesResult.IsNull())
                {
                    ProductPricesLogDetailRequest productPricesLogDetailRequest = new ProductPricesLogDetailRequest()
                    {
                        ProductId          = request.ProductId,
                        PriceTypeId        = i,
                        Price              = price,
                        ProductPriceLogsId = 0,
                        CreatedBy          = currentUserId,
                        CreatedTime        = DateTime.Now,
                    };
                    _productServices.SaveProductLogPrices(productPricesLogDetailRequest);
                }
                ProductPricesDetailRequest productPricesDetailRequest = new ProductPricesDetailRequest()
                {
                    ProductId   = request.ProductId,
                    PriceTypeId = i,
                    Price       = price
                };
                _productServices.UpdateProductPrice(productPricesDetailRequest);
            }
            #endregion

            var productLogDetailRequest = new ProductLogDetailRequest()
            {
                ProductLogsId      = 0,
                ProductId          = request.ProductId,
                ProductCode        = request.ProductCode,
                ProductDescription = request.ProductDescription,
                Quantity           = request.Quantity,
                //UnitPrice = request.UnitPrice,
                IsActive     = request.IsActive,
                CreatedBy    = request.ModifiedBy,
                CreatedTime  = DateTime.Now,
                ModifiedBy   = null,
                ModifiedTime = null,
                CategoryId   = request.CategoryId
            };
            var productLogResult = _productServices.SaveProductLogs(productLogDetailRequest);

            if (productLogResult <= 0)
            {
                return(Json(new { isSucess = isSucess, messageAlert = Messages.ServerError }, JsonRequestBehavior.AllowGet));
            }

            isSucess = true;
            var response = new
            {
                isSucess     = isSucess,
                messageAlert = messageAlert
            };
            return(Json(response, JsonRequestBehavior.AllowGet));
            //}
            //else
            //{

            //    var errors = ModelState.Values.SelectMany(v => v.Errors)
            //               .ToList();
            //    foreach (var err in errors)
            //    {
            //        Logging.Information("(Response-Model-Stocks) UpdateProductDetails : " + err.ErrorMessage);
            //    }

            //    return Json(new { isSucess = isSucess, messageAlert = Messages.ErrorOccuredDuringProcessing }, JsonRequestBehavior.AllowGet);
            //}
        }