Exemplo n.º 1
0
        public async Task <IActionResult> PutFavorite(int id, Favorite favorite)
        {
            if (id != favorite.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutShopAccount(string id, ShopAccount shopAccount)
        {
            if (id != shopAccount.Username)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutDeliveryAddress(int id, DeliveryAddress deliveryAddress)
        {
            if (id != deliveryAddress.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutOrderingDetail(int id, OrderingDetail orderingDetail)
        {
            if (id != orderingDetail.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> updateDefaultDeliveryId([FromBody] UpdateDeliveryIdModel deliveryId) //username only
        {
            var currentAccount = _context.Account.Find(User.Identity.Name);

            if (currentAccount != null)
            {
                currentAccount.DefaultDeliveryId = deliveryId.deliveryId;
                _context.Account.Update(currentAccount);
                await _context.SaveChangesAsync();

                currentAccount = await _context.Account.Include(a => a.DeliveryAddress).Include(a => a.Favorite).ThenInclude(f => f.Product).FirstOrDefaultAsync(a => a.Username.Equals(currentAccount.Username));

                return(Ok(currentAccount));
            }
            return(NotFound());
        }