コード例 #1
0
        public JsonResult UpdateInventorySalesOrder(SalesOrderRequest request)
        {
            bool   isSucess = false;
            string messageAlert = string.Empty, orderTransactionTypeService = string.Empty;
            long   updateOrderTransactionResult = 0;
            long   salesOrderIdResult           = 0;

            OrderTransactionRequest     orderTransactionRequest       = new OrderTransactionRequest();
            List <ProductDetailRequest> orderTransactionDetailRequest = new List <ProductDetailRequest>();

            var currentUserId = Session[LookupKey.SessionVariables.UserId].IsNull() ? 0 : Convert.ToInt64(Session[LookupKey.SessionVariables.UserId]);

            if (ModelState.IsValid)
            {
                #region Set Order Transaction Type

                if (request.OrderTransactionType == LookupKey.OrderTransactionType.SalesOrder)
                {
                    orderTransactionTypeService = "SalesOrderService";
                }

                #endregion

                #region Service implementation

                orderTransactionRequest.CreatedBy          = currentUserId;
                orderTransactionRequest.CustomerId         = request.CustomerId;
                orderTransactionRequest.SalesOrderId       = request.SalesOrderId;
                orderTransactionRequest.SalesOrderStatusId = request.SalesOrderStatusId;
                orderTransactionRequest.SalesNo            = request.SalesNo;
                orderTransactionRequest.ModeOfPayment      = request.ModeOfPayment;
                orderTransactionRequest.ShippingFee        = request.ShippingFee;

                #region Validation for CurrentStocks
                List <long>   productIdCollections       = new List <long>();
                List <string> productCodeWithCorrections = new List <string>();
                foreach (var salesOrderDetails in request.SalesOrderProductDetailRequest)
                {
                    productIdCollections.Add(salesOrderDetails.ProductId);
                }

                var currentStockInventory = _productServices.GetAll().Where(m => productIdCollections.Contains(m.ProductId)).ToList();

                foreach (var salesDetails in request.SalesOrderProductDetailRequest)
                {
                    var currentStocks = currentStockInventory.Where(m => m.ProductId == salesDetails.ProductId).FirstOrDefault();
                    if (currentStocks.Quantity < salesDetails.Quantity)
                    {
                        productCodeWithCorrections.Add(currentStocks.ProductCode);
                    }
                }

                if (productCodeWithCorrections.Count > 0)
                {
                    var currentStockMessage = "";
                    if (productCodeWithCorrections.Count == 1)
                    {
                        currentStockMessage = productCodeWithCorrections.FirstOrDefault().ToString();
                    }
                    else
                    {
                        for (int i = 0; i < productCodeWithCorrections.Count; i++)
                        {
                            if (i == 0)
                            {
                                currentStockMessage = productCodeWithCorrections[i].ToString();
                            }
                            else
                            {
                                currentStockMessage += ", " + productCodeWithCorrections[i].ToString();
                            }
                        }
                    }
                    var x = string.Format(Messages.CurrentStockValidation, currentStockMessage);
                    return(Json(new
                    {
                        isSuccess = isSucess,
                        messageAlert = string.Format(Messages.CurrentStockValidation, currentStockMessage),
                        salesOrderIdResult = salesOrderIdResult
                    }, JsonRequestBehavior.AllowGet));
                }
                #endregion



                foreach (var salesOrderDetails in request.SalesOrderProductDetailRequest)
                {
                    orderTransactionDetailRequest.Add(new ProductDetailRequest()
                    {
                        ProductId   = salesOrderDetails.ProductId,
                        UnitPrice   = salesOrderDetails.UnitPrice,
                        Quantity    = salesOrderDetails.Quantity,
                        PriceTypeId = salesOrderDetails.PriceTypeId,
                        CreatedBy   = currentUserId,
                    });
                }
                var type = Type.GetType(string.Format("{0}.{1}, {0}", "Business.AAA.Core", orderTransactionTypeService));
                IOrderTransactionalServices order = (IOrderTransactionalServices)Activator.CreateInstance(type,
                                                                                                          _productServices,
                                                                                                          _orderServices,
                                                                                                          _customerServices);
                updateOrderTransactionResult = order.UpdateOrderTransaction(
                    ref orderTransactionRequest,
                    orderTransactionDetailRequest);

                #endregion

                //IOrderTransactionalServices x = new PurchaseOrderService(_productServices, _orderServices);
                //var type = Type.GetType("Business.AAA.Core.PurchaseOrderService, Business.AAA.Core");
                //updateOrderTransactionResult = x.UpdateOrderTransaction(orderTransactionRequest, orderTransactionDetailRequest);

                if (updateOrderTransactionResult == -100)
                {
                    return(Json(new { isSuccess = isSucess, messageAlert = Messages.ProductCodeValidation, salesOrderIdResult = salesOrderIdResult }, JsonRequestBehavior.AllowGet));
                }
                else if (updateOrderTransactionResult == 0)
                {
                    isSucess = true;
                }

                salesOrderIdResult = orderTransactionRequest.SalesOrderId;
                var response = new
                {
                    isSuccess          = isSucess,
                    messageAlert       = messageAlert,
                    salesOrderIdResult = salesOrderIdResult
                };
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { isSuccess = isSucess, messageAlert = Messages.ErrorOccuredDuringProcessing, salesOrderIdResult = salesOrderIdResult }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public JsonResult UpdateInventoryOrder(OrderRequest request)
        {
            bool   isSucess = false;
            string messageAlert = string.Empty, orderTransactionTypeService = string.Empty;
            long   updateOrderTransactionResult = 0;

            OrderTransactionRequest     orderTransactionRequest       = new OrderTransactionRequest();
            List <ProductDetailRequest> orderTransactionDetailRequest = new List <ProductDetailRequest>();

            var currentUserId = Session[LookupKey.SessionVariables.UserId].IsNull() ? 0 : Convert.ToInt64(Session[LookupKey.SessionVariables.UserId]);

            if (ModelState.IsValid)
            {
                #region Set Order Transaction Type


                if (request.OrderTransactionType == LookupKey.OrderTransactionType.PurchaseOrder)
                {
                    orderTransactionTypeService = "PurchaseOrderService";
                }
                else if (request.OrderTransactionType == LookupKey.OrderTransactionType.SalesOrder)
                {
                    orderTransactionTypeService = "SalesOrderService";
                }
                else if (request.OrderTransactionType == LookupKey.OrderTransactionType.CorrectionOrder)
                {
                    orderTransactionTypeService = "CorrectionOrderService";
                }

                #endregion

                #region Service implementation

                orderTransactionRequest.CreatedBy = currentUserId;

                orderTransactionDetailRequest.Add(new ProductDetailRequest()
                {
                    ProductId          = request.ProductId,
                    ProductCode        = request.ProductCode,
                    ProductDescription = request.ProductDescription,
                    Quantity           = request.Stocks,

                    CategoryId    = request.CategoryId,
                    IsActive      = request.IsActive,
                    CreatedBy     = currentUserId,
                    Remarks       = request.Remarks,
                    ProductPrices = request.ProductPrices,
                    RetailerPrice = request.RetailerPrice,
                    ResellerPrice = request.ResellerPrice,
                    BigBuyerPrice = request.BigBuyerPrice,
                });
                var type = Type.GetType(string.Format("{0}.{1}, {0}", "Business.AAA.Core", orderTransactionTypeService));
                IOrderTransactionalServices order = (IOrderTransactionalServices)Activator.CreateInstance(type,
                                                                                                          _productServices,
                                                                                                          _orderServices,
                                                                                                          _customerServices);
                updateOrderTransactionResult = order.UpdateOrderTransaction(
                    ref orderTransactionRequest,
                    orderTransactionDetailRequest);

                #endregion

                //IOrderTransactionalServices x = new PurchaseOrderService(_productServices, _orderServices);
                //var type = Type.GetType("Business.AAA.Core.PurchaseOrderService, Business.AAA.Core");
                //updateOrderTransactionResult = x.UpdateOrderTransaction(orderTransactionRequest, orderTransactionDetailRequest);

                if (updateOrderTransactionResult == -100)
                {
                    return(Json(new { isSucess = isSucess, messageAlert = Messages.ProductCodeValidation }, JsonRequestBehavior.AllowGet));
                }
                else if (updateOrderTransactionResult == 0)
                {
                    isSucess = true;
                }

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