예제 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var existing = db.Orders.Any(o => o.Id == id);
                if (!existing)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutRestaurant(int id, Restaurant restaurant)
        {
            if (id != restaurant.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #3
0
 public async Task <bool> UpdatePeriodicElementAsync(PeriodicElement element)
 {
     try
     {
         var periodicElement = _context.PeriodicElements.FirstOrDefault(p => p.Id == element.Id);
         _context.Entry(periodicElement).CurrentValues.SetValues(element);
         return(await _context.SaveChangesAsync() > 0 ? true : false);
     }
     catch (Exception exp)
     {
         _Logger.LogError($"Error in {nameof(UpdatePeriodicElementAsync)}: " + exp.Message);
     }
     return(false);
 }
예제 #4
0
        public async Task <bool> UpdateCustomerAsync(Customer customer)
        {
            try
            {
                var customerFromRepo = await GetCustomerAsync(customer.Id);

                _Context.Entry(customerFromRepo).CurrentValues.SetValues(customer);
                return(await _Context.SaveChangesAsync() > 0 ? true : false);
            }
            catch (Exception exp)
            {
                _Logger.LogError($"Error in {nameof(UpdateCustomerAsync)}: " + exp.Message);
            }
            return(false);
        }