public async Task <ActionResult> createOrder(OrderDto model) { double totalAmount = 0; foreach (var item in model.OrderDetail) { if (item.Quantity <= 0 || item.Quantity > 5) { return(BadRequest()); } var product = _productService.GetProduct(item.ProductId); if (product == null) { return(BadRequest()); } totalAmount += product.CurrentPrice * item.Quantity; } var order = model.Adapt <Order>(); order.TotalAmount = totalAmount; order.Status = OrderCurrentStatus.received.ToString(); _orderService.CreateOrder(order); foreach (var item in model.OrderDetail) { var orderDetail = item.Adapt <OrderDetail>(); orderDetail.OrderId = order.Id; _detailService.CreateOrderDetail(orderDetail); } _orderService.SaveChanges(); return(Ok()); }
//JQuery Ajax calls go public JsonResult SaveOrderdetailsRow(OrderDetail orderDetail) { bool status = false; OrderDetail savedOrderRow = null; try { ItemWarehouse itemWareHouse = itemWarehouseService.GetItemWarehouse(orderDetail.WarehouseID); Order order = orderService.GetOrder(orderDetail.OrderID); if (order != null) { orderDetail.WarehouseID = itemWareHouse.WarehouseID; orderDetailService.CreateOrderDetail(orderDetail); order.TotalPrice += orderDetail.Extended_Price; orderService.UpdateOrder(order); orderDetailService.SaveOrderDetail(); orderService.SaveOrder(); savedOrderRow = orderDetailService.GetSavedOrderDetail(orderDetail); if (savedOrderRow != null) { status = true; } } } catch (Exception e) { } return(new JsonResult { Data = new { status = status } }); }
public IActionResult Create(OrderDetail orderDetail) { if (ModelState.IsValid) { if (orderDetailService.CreateOrderDetail(orderDetail) > 0 && orderDetail.Quantity > 0) { return(RedirectToAction("WatchOrderDetail", "OrderDetail", orderDetailService.GetOrderByid(orderDetail.OrderId))); } else { ModelState.AddModelError("", "Quantity is not Null"); } } else { ModelState.AddModelError("", "Some thing wrong"); } return(View(orderDetail)); }
/// <summary> /// Creates the oder. /// </summary> /// <param name="UserId">The user identifier.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public async Task <bool> CreateOder(CreateOrderModel model) { var order = _orderRepository.Insert(new TblOrder { OrderId = Guid.NewGuid(), DateCreate = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, Total = await _cartService.TotalMoney(model.UserId), UserId = model.UserId, }); var query = _cartRepository.GetManyAsNoTracking(x => x.UserId == model.UserId); foreach (TblCart element in query.ToList()) { await _orderDetailService.CreateOrderDetail(order.Entity.OrderId, element.Quantity, element.ProductId); } await _cartService.DeleteCart(model.UserId); await _unitOfWork.CommitAsync(); return(true); }
public async Task <ActionResult> createOrder(OrderCM model) { double totalAmount = 0; foreach (var item in model.OrderDetailCMs) { if (item.Quantity <= 0 || item.Quantity > 5) { return(BadRequest()); } var product = _productService.GetProduct(item.ProductId); if (product == null) { return(BadRequest()); } totalAmount += product.CurrentPrice * item.Quantity; } var user = await _userManager.GetUserAsync(User); var order = model.Adapt <Order>(); order.BuyerId = user.Id; order.TotalAmount = totalAmount; order.CurrentStatus = (int)OrderCurrentStatus.received; _orderService.CreateOrder(order); foreach (var item in model.OrderDetailCMs) { var orderDetail = item.Adapt <OrderDetail>(); orderDetail.OrderId = order.Id; _detailService.CreateOrderDetail(orderDetail); } _orderService.SaveChanges(); OrderStatus status = new OrderStatus(); status.OrderId = order.Id; status.StatusId = (int)OrderStatusId.start; _statusService.CreateOrderStatus(status); _statusService.SaveChanges(); return(Ok()); }
public async Task <IActionResult> CreateOrder([FromBody] createOrderDetailViewModel model) { var result = await _orderdetailService.CreateOrderDetail(model); return(Ok(result)); }