Example #1
0
 public async Task <IActionResult> AddOrder(OrderDto orderForCreation)
 {
     if (orderForCreation != null)
     {
         var orderToCreation = _mapper.Map <Order>(orderForCreation);
         if (await _repo.AddItemAsync(orderToCreation))
         {
             return(Ok(orderToCreation));
         }
         return(BadRequest());
     }
     return(BadRequest());
 }
Example #2
0
        public async Task <IActionResult> Cart(string code)
        {
            if (!string.IsNullOrEmpty(code))
            {
                await orderRepository.AddItemAsync(code);
            }

            var order = await orderRepository.GetOrderAsync();

            List <OrderItem> itens         = order.Itens;
            CartViewModel    cartViewModel = new CartViewModel(itens);

            return(View(cartViewModel));
        }
        public async Task <IActionResult> AddOrder(ClientForOrderDto clientDto)
        {
            if (clientDto != null)
            {
                clientDto.DeliveryMethod = clientDto.DeliveryMethod.Substring(3);
                clientDto.PaymentMethod  = clientDto.PaymentMethod.Substring(3);
                Client client = new Client
                {
                    ClientName     = clientDto.ClientName,
                    ClientSurname  = clientDto.ClientSurname,
                    Patronymic     = clientDto.Patronymic,
                    PhoneNumber    = clientDto.PhoneNumber,
                    Email          = clientDto.Email,
                    DeliveryMethod = clientDto.DeliveryMethod,
                    Place          = clientDto.Place,
                    PlaceNumber    = clientDto.PlaceNumber,
                    PaymentMethod  = clientDto.PaymentMethod
                };
                await _clRepo.AddItemAsync(client);

                Client clientForOrder = _clRepo.AllItems.LastOrDefault();
                double sum            = 0;
                var    strOrds        = await _strOrdRepo.AllItems.Where(s => s.OrderId == 0).ToListAsync();

                foreach (var item in strOrds)
                {
                    sum += item.Amount;
                }
                if (clientForOrder != null)
                {
                    Order orderToDb = new Order
                    {
                        ClientId      = clientForOrder.Id,
                        SumOrder      = sum,
                        DateTimeOrder = DateTime.Now,
                        StatusId      = 1
                    };
                    await _ordRepo.AddItemAsync(orderToDb);

                    foreach (var item in strOrds)
                    {
                        item.OrderId = orderToDb.Id;
                        await _strOrdRepo.ChangeItemAsync(item);
                    }
                    return(Ok());
                }
            }
            return(BadRequest());
        }