Ejemplo n.º 1
0
        public async Task <bool> IncreaseQuantity(string orderId)
        {
            NutriAnimal.Data.Models.Order orderFromDb = await this.context.Orders
                                                        .SingleOrDefaultAsync(order => order.Id == orderId);

            if (orderFromDb == null)
            {
                throw new ArgumentNullException(nameof(orderFromDb));
            }

            orderFromDb.Quantity++;

            this.context.Update(orderFromDb);
            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Ejemplo n.º 2
0
        public async Task <bool> CreateOrder(OrderServiceModel orderServiceModel)

        {
            var productFromDb = this.context.Products.SingleOrDefault(product => product.Id == orderServiceModel.ProductId);
            var order         = new NutriAnimal.Data.Models.Order
            {
                ProductId = orderServiceModel.ProductId,
                Quantity  = orderServiceModel.Quantity,
                OrderedOn = DateTime.UtcNow,
                IssuerId  = orderServiceModel.IssuerId,
            };
            var price = productFromDb.Price;

            order.TotalPrice = price;
            var status = this.context.Statuses.FirstOrDefault(statusDb => statusDb.Name == "Active");

            order.Status = status;

            this.context.Orders.Add(order);
            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }