Ejemplo n.º 1
0
        public async Task <IActionResult> PutCart(int id, Cart cart)
        {
            if (id != cart.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Product> > PostProduct([FromBody] Product productItem)
        {
            if (productItem == null)
            {
                return(BadRequest(new { message = "Invalid product. Please check" }));
            }

            _context.Product.Add(productItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostProduct", new { id = productItem.Id }, new { message = "Success. " + "Product ID: " + productItem.Id }));
        }
        public async Task <ActionResult> Register([FromBody] User user)
        {
            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password))
            {
                return(BadRequest());
            }

            if (UserExists(user))
            {
                return(Conflict());
            }

            _context.User.Add(user);
            await _context.SaveChangesAsync();

            return(Created("", new { id = user.Id }));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Card> > saveCardDetails([FromBody] Card card)
        {
            try
            {
                bool isExistingCard = _context.Card.Any(c => c.CardNo == card.CardNo);

                if (isExistingCard)
                {
                    return(NoContent());
                }
                else
                {
                    _context.Card.Add(card);
                    await _context.SaveChangesAsync();

                    return(Created("", new { card = card }));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong. Please check exception trace. " + e.Message);
                return(StatusCode(500));
            }
        }