public IActionResult GetOrders() { var orders = _orderRepository.Get(includeDetails: true); List <OrderDto> ordersDto = orders.Select(it => OrderDto.ConvertFromOrder(it)).ToList(); return(Ok(ordersDto)); }
public IActionResult GetOrder(int id) { var order = _orderRepository.Get(id, includeDetails: true); if (order == null) { return(NotFound()); } var orderDto = OrderDto.ConvertFromOrder(order); return(Ok(orderDto)); }
public async Task <IActionResult> SaveOrderAsync([FromBody] SaveOrderDto saveOrderDto) { if (!ModelState.IsValid) { return(BadRequest()); } var loggedUser = await _userManager.GetUserAsync(HttpContext.User); var order = Order.ConvertFromSaveOrderDto(saveOrderDto, DateTime.Now, loggedUser); var savedOrder = _orderRepository.Save(order); var retVal = OrderDto.ConvertFromOrder(savedOrder); return(Ok(retVal)); }
public async Task <IActionResult> UpdateAsync(int id, [FromBody] SaveOrderDto saveOrderDto) { if (!ModelState.IsValid) { return(BadRequest()); } var order = _orderRepository.Get(id); if (order == null) { return(NotFound()); } order.ConvertFormSaveOrderDto(saveOrderDto); _unitOfWork.SaveChanges(); var updatedOrder = _orderRepository.Get(order.Id); return(Ok(OrderDto.ConvertFromOrder(updatedOrder))); }