public async Task <ServiceResponse <GetRestaurantDTO> > UpdateRestaurant(UpdateRestaurantDTO updateRestaurant) { ServiceResponse <GetRestaurantDTO> serviceResponse = new ServiceResponse <GetRestaurantDTO>(); try { Restaurant restaurant = await _context.Restaurants.FirstOrDefaultAsync(c => c.Id == updateRestaurant.Id); restaurant.Name = updateRestaurant.Name; restaurant.Cuisine = updateRestaurant.Cuisine; restaurant.Location = updateRestaurant.Location; restaurant.Visited = updateRestaurant.Visited; restaurant.Deleted = updateRestaurant.Deleted; restaurant.DateVisited = updateRestaurant.DateVisited; _context.Restaurants.Update(restaurant); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetRestaurantDTO>(restaurant); } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> UpdateRestaurant(UpdateRestaurantDTO updateRestaurant) { ServiceResponse <GetRestaurantDTO> response = await _restaurantService.UpdateRestaurant(updateRestaurant); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public async Task UpdateAsync(int id, UpdateRestaurantDTO dto) { var restaurant = await _efCoreRestaurantRepository.Get(id); if (restaurant == null) { throw new NotFoundExpection("Restaurant not found"); } var userAu = _userContextService.User.IsInRole("Admin"); if (!userAu) { throw new ForbidException("Nie masz dostępu"); } restaurant.Name = dto.Name; restaurant.Description = dto.Description; restaurant.HasDelivery = dto.HasDelivery; await _efCoreRestaurantRepository.Update(restaurant); }
public async Task <ActionResult> UpdateAsync([FromRoute] int id, [FromBody] UpdateRestaurantDTO dto) { await restaurantService.UpdateAsync(id, dto); return(NoContent()); }