public static void CopyFromEntity(AddTeleOrderResponse dto, TeleOrder order) { if (dto.order_details == null) { dto.order_details = new TeleOrderDto(); } dto.order_details.order_id = order.TeleOrdID; // order_status dto.order_details.invoice_number = order.InvoiceNumber; dto.order_details.order_status = order.MOrderStatu.OrderStatus; }
public AddTeleOrderResponse AddTeleOrder(AddTeleOrderRequest request) { AddTeleOrderResponse response = new AddTeleOrderResponse(); try { AgentAdmin admin = AgentAdminServices.GetAuthAdmin(request.user_id, request.auth_token, response); if (admin == null) { return(response); } if (request.delivery_date <= DateTime.MinValue) { _orderService.MakeInvalidDeliveryDateFormat(response); return(response); } UpdateTeleOrderRequest(request); // To update request from mobile, Reason : not passing expected values from mobile TeleCustomer cons = new TeleCustomer(); cons.Address = request.customer_details.customer_address; cons.CustomerName = request.customer_details.customer_name; cons.MobileNumber = request.customer_details.customer_mobile; cons.StatusId = true; //cons.Latitude = request.customer_details.latitude; //cons.Longitude = request.customer_details.longitude; cons.CreatedBy = admin.AgadmID; cons.CreatedDate = DateTime.Now; TeleOrder ord = new TeleOrder(); PopulateOrder(ord, cons.TeleCustID, request, admin); AddProductsToOrder(ord, request.products); ord.DrvrID = request.driver_id; ord.DeliverySlotID = (short)request.time_slot_id; //ord.DeliveredDate = null; using (TeleOrderDao odao = new TeleOrderDao()) { if (request.has_exchange) { if (request.exchange == null) { _orderService.MakeInvalidExchangeInputResponse(response); return(response); } foreach (ExchangeDto exdto in request.exchange) { TeleOrderPrdocuctExchange opex = new TeleOrderPrdocuctExchange(); ProductExchange pxg = odao.FindProductExchangeById(exdto.exchange_id); if (pxg == null) { _orderService.MakeInvalidExchangeInputResponse(response); return(response); } opex.ProdID = pxg.ProdID; opex.ExchangePrice = exdto.exchange_price; opex.CreatedDate = DateTime.Now; opex.ExchangePromoPrice = exdto.exchange_promo_price * exdto.exchange_quantity; opex.ExchangeQuantity = exdto.exchange_quantity; opex.ExchangeWith = exdto.exchange_with; opex.StatusId = true;//TODO opex.SubTotal = exdto.exchange_price * exdto.exchange_quantity; //ord.GrandTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity; var product = request.products.Where(p => p.product_id == pxg.ProdID).FirstOrDefault(); if (product == null) { //MakeInvalidExchangeInputResponse(response); response.code = 1; response.has_resource = 0; response.message = "Cannot find product with id " + pxg.ProdID + " in the products array"; return(response); } opex.TotalAmount = opex.SubTotal + opex.ExchangePromoPrice + (product.shipping_cost * exdto.exchange_quantity) + (product.shipping_promo * exdto.exchange_quantity); ord.TeleOrderPrdocuctExchanges.Add(opex); ord.ShippingCharge += (product.shipping_cost * exdto.exchange_quantity); ord.PromoShipping += (product.shipping_promo * exdto.exchange_quantity); ord.NumberOfProducts += exdto.exchange_quantity; ord.ExchangeSubTotal += opex.SubTotal; ord.PromoExchange += opex.ExchangePromoPrice; ord.GrantTotal += opex.TotalAmount; } } //cons.TeleOrder = ord; odao.Insert(ord); cons.TeleOrdID = ord.TeleOrdID; using (TeleOrderCustomerDao tcDao = new TeleOrderCustomerDao()) { tcDao.Insert(cons); } ord = odao.FindById(ord.TeleOrdID, true); TeleOrderHelper.CopyFromEntity(response, ord); response.code = 0; response.has_resource = 1; response.message = MessagesSource.GetMessage("add.tele.order"); } } catch (Exception ex) { response.MakeExceptionResponse(ex); } return(response); }
public NegotiatedContentResult <AddTeleOrderResponse> PostAddTeleOrder([FromBody] AddTeleOrderRequest request) { AddTeleOrderResponse resp = _teleorderServices.AddTeleOrder(request); return(Content(HttpStatusCode.OK, resp)); }