public ActionResult CreateOrder([FromBody] OrderCM model) { var timeCreate = DateTime.Now; var checkSlot = _slotService.GetSlots(s => s.TimeStart.Date == timeCreate.Date).Where(t1 => t1.TimeStart.TimeOfDay <= timeCreate.TimeOfDay).Where(t2 => t2.TimeEnd.TimeOfDay >= timeCreate.TimeOfDay).ToList(); if (checkSlot.Any()) { var checkCus = _customerService.GetCustomer(model.CustomerId.Value); if (checkCus == null) { return(NotFound()); } Order newOrder = model.Adapt <Order>(); newOrder.IsDelete = false; newOrder.SlotTakeId = checkSlot[0].Id; _orderService.CreateOrder(newOrder); _orderService.Save(); foreach (var item in model.ListOrderServices) { OrderService orderService = item.Adapt <OrderService>(); orderService.OrderId = newOrder.Id; _orderServiceService.CreateOrderService(orderService); } _orderServiceService.Save(); return(Ok(200)); } else { return(BadRequest("Dont Have Any Slot")); } }
public ActionResult CreateService([FromBody] OrderServiceCM model) { if (_orderService.GetOrder(model.OrderId.Value) == null) { return(BadRequest(401)); } if (_serviceService.GetService(model.ServiceId.Value) == null) { return(BadRequest(401)); } OrderService orderService = model.Adapt <OrderService>(); orderService.IsDelete = false; _orderServiceService.CreateOrderService(orderService); _orderServiceService.Save(); return(Ok(200)); }