Beispiel #1
0
        public async Task <IActionResult> InitialiseCart(CartModel Cart)
        {
            var c = _context.Carts.Where(crt1 => crt1.IdUser == Cart.UserId);

            if (c.Any())
            {
                return(BadRequest("Card alraedy created"));
            }
            Cart crt = new Cart();

            // just to test adding
            var user = await _userManager.FindByIdAsync(Cart.UserId);

            crt.IdUser     = _context.ApplicationUsers.Single(a => a.Id == Cart.UserId).Id;
            crt.TotalPrice = 0;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Carts.Add(crt);
            await _context.SaveChangesAsync();

            return(Ok("Cart Created"));
        }
        public async Task <IActionResult> PutProduitEncher([FromRoute] int id, [FromBody] ProduitEncher produitEncher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != produitEncher.idProduit)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }