public virtual IActionResult CreateSalesorder([FromBody] SalesOrderRequest body) { ServiceResponse <SalesOrderResponse> serviceResponse = new ServiceResponse <SalesOrderResponse>(); int?orderid = _orderRepository.Add(new Order() { CustomerID = body.CustomerID, OrderDate = DateTime.Now.ToString() }); List <OrderItem> orderItems = new List <OrderItem>(); foreach (var item in body.OrderItemRequestList.SalesOrders) { orderItems.Add(new OrderItem() { OrderID = orderid, ProductID = item.ProductID, Quantity = item.Quantity }); } foreach (var item in orderItems) { int?orderItemid = _orderItemRepository.Add(item); } if (orderid > 0) { SalesOrderResponse response = new SalesOrderResponse() { OrderID = orderid, Message = "Saved Successfully." }; serviceResponse.SetSuccess(response); } else { serviceResponse.SetError(MethodBase.GetCurrentMethod().Name, ServiceResponseStatus.Error, "", "", string.Empty); } return(Ok(serviceResponse)); }
public IActionResult UpdateSalesOrder([FromBody] SalesOrderRequest request) { bool isSucess = false; string messageAlert = string.Empty; long updateOrderTransactionResult = 0; OrderTransactionRequest orderTransactionRequest = new OrderTransactionRequest(); List <OrderTransactionDetailRequest> orderTransactionDetailRequest = new List <OrderTransactionDetailRequest>(); var currentUserId = HttpContext.Session.GetString(LookupKey.SessionVariables.UserId).IsNull() ? 0 : Convert.ToInt64(HttpContext.Session.GetString(LookupKey.SessionVariables.UserId)); #region Service implementation orderTransactionRequest.CreatedBy = currentUserId; orderTransactionRequest.Messenger = request.Messenger; orderTransactionRequest.PaymentTerms = request.PaymentTerms; orderTransactionRequest.CustomerId = request.CustomerId; orderTransactionRequest.IsOrderQueue = false; var type = Type.GetType(string.Format("{0}.{1}, {0}", "Business.InventoryIO.Core", "SalesOrderService")); IOrderService order = (IOrderService)Activator.CreateInstance(type, _productService, _customerService, _salesOrderService, _salesOrderDetailService); updateOrderTransactionResult = order.UpdateOrderTransacion( orderTransactionRequest, request.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 == 0) { isSucess = true; } var response = new { isSucess = isSucess, messageAlert = messageAlert }; return(Ok(response)); }
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)); } }