Ejemplo n.º 1
0
        public async Task <IActionResult> Create(ShoppingCartHeaderRequest shoppingCartHeaderRequest)
        {
            var randomGenerator       = new Random();
            var ShoppingCartItemsList = shoppingCartHeaderRequest.shoppingCartItemsRequests
                                        .Select(shoppingCartItemRequest => new ShoppingCartItems
            {
                Description = shoppingCartItemRequest.Description,
                IdProduct   = shoppingCartItemRequest.IdProduct,
                Price       = shoppingCartItemRequest.Price,
                Qty         = shoppingCartItemRequest.Qty,
                Total       = shoppingCartItemRequest.Price * shoppingCartItemRequest.Qty,
            }).ToList();

            var shoppingCartHeader = new ShoppingCartHeader
            {
                IdCustomer        = shoppingCartHeaderRequest.IdCustomer,
                IsCredit          = shoppingCartHeaderRequest.IsCredit,
                OrderAmount       = shoppingCartHeaderRequest.OrderAmount,
                ShoppingCartItems = ShoppingCartItemsList,
                Active            = true,
                OrderDate         = DateTime.Now,
                OrderNumber       = randomGenerator.Next(1000000000, 999999999).ToString(),
            };

            try
            {
                var response = await _shoppingCartHeaderManager.CreateOrder(shoppingCartHeader);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(""));
            }
        }
Ejemplo n.º 2
0
        public async Task <ShoppingCartHeader> CreateOrder(ShoppingCartHeader shoppingCartHeader)
        {
            var result = _shoppingContext.ShoppingCartHeader.Add(shoppingCartHeader);
            await _shoppingContext.SaveChangesAsync();

            return(result.Entity);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutShoppingCartHeader(int id, ShoppingCartHeader shoppingCartHeader)
        {
            if (id != shoppingCartHeader.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShoppingCartHeaderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <ShoppingCartHeader> > PostShoppingCartHeader(ShoppingCartHeader shoppingCartHeader)
        {
            _context.ShoppingCartHeader.Add(shoppingCartHeader);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetShoppingCartHeader", new { id = shoppingCartHeader.Id }, shoppingCartHeader));
        }