public async Task <IActionResult> PutOrderItem([FromRoute] int id, [FromBody] OrderItem orderItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderItem.OrderItemId)
            {
                return(BadRequest());
            }

            _context.Entry(orderItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(orderItem));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
        public async Task <IActionResult> PutProduct([FromRoute] string id, [FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(product));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> PutSalesperson([FromRoute] int id, [FromBody] Salesperson salesperson)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != salesperson.SalespersonId)
            {
                return(BadRequest());
            }

            _context.Entry(salesperson).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(salesperson));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SalespersonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 4
0
        public async Task <Product> Add(Product product)
        {
            await _context.Product.AddAsync(product);

            await _context.SaveChangesAsync();

            return(product);
        }
Esempio n. 5
0
        public async Task <OrderItem> Add(OrderItem orderItem)
        {
            await _context.OrderItem.AddAsync(orderItem);

            await _context.SaveChangesAsync();

            return(orderItem);
        }
Esempio n. 6
0
        public async Task <Order> Add(Order order)
        {
            await _context.Order.AddAsync(order);

            await _context.SaveChangesAsync();

            return(order);
        }
Esempio n. 7
0
        public async Task <Salesperson> Add(Salesperson salesperson)
        {
            await _context.Salesperson.AddAsync(salesperson);

            await _context.SaveChangesAsync();

            return(salesperson);
        }
Esempio n. 8
0
        public async Task <Customer> Add(Customer customer)
        {
            await _context.Customer.AddAsync(customer);

            await _context.SaveChangesAsync();

            return(customer);
        }
Esempio n. 9
0
        public async Task<Order> CreateOrder(int customerId, int salesPersonId, List<Tuple<string, int>> productsQuantities)
        {
            var order = _orderRepo.Create(new NewOrderInformation()
            {
                CustomerId = customerId,
                SalesPersonId = salesPersonId,
                products = productsQuantities.Select(p =>
                {
                    return new ProductOrderInformation()
                    {
                        ProductCode = p.Item1,
                        Quantity = p.Item2,
                        Price = GetPriceWithDiscounts(p.Item1, p.Item2)
                    };
                }).ToList()
            });

            await _context.SaveChangesAsync();
            _userNotifier.NotifyUser(customerId);
            return order;
        }