public IActionResult UpdateRestaurant([FromRoute] long id, [FromBody] UpdateRestaurantRequest updateRestaurant) { addUpdateRequestValidator.ValidateAndThrow(updateRestaurant); var restaurant = restaurantRepository.UpdateRestaurant(id, updateRestaurant); return(Ok(restaurant)); }
public static RestaurantEntity ToEntity(this UpdateRestaurantRequest restaurant) { return(new RestaurantEntity { Id = restaurant.Id, Name = restaurant.Name, Address = restaurant.Address }); }
public long UpdateRestaurant(long id, UpdateRestaurantRequest updateRestaurant) { var restaurant = context.Restaurants.FirstOrDefault(x => x.Id == id); restaurant.Adress = updateRestaurant.Adress; restaurant.City = updateRestaurant.City; context.Update(restaurant); context.SaveChanges(); return(restaurant.Id); }
public async Task UpdateRestaurant(UpdateRestaurantRequest restaurantRequest) { await repository.UpdateRestaurant(restaurantRequest.ToEntity()); }
public ActionResult Update([FromRoute] int id, [FromBody] UpdateRestaurantRequest request) { _restaurantService.Update(id, request); return(NoContent()); }
public async Task UpdateRestaurant(UpdateRestaurantRequest restaurantRequest) { await restaurantValidatorFactory.CreateUpdateRestaurantValidator().ThrowIfNotValid(restaurantRequest); await restaurantService.UpdateRestaurant(restaurantRequest); }
public async Task <IActionResult> UpdateRestaurant([FromRoute] Guid restaurantId, [FromBody] UpdateRestaurantRequest updateRestaurantRequest) { /* var userOwnsRestaurant = await _restaurantService * .UserOwnsRestaurantAsync(restaurantId, HttpContext.GetUserId()); * * if (!userOwnsRestaurant) * { * return BadRequest(); * }*/ var restaurant = await _restaurantService .GetRestaurantByIdAsync(restaurantId); var query = await _context.RestaurantCategories .Where(x => x.Id == updateRestaurantRequest .CategoryToRestaurantRequest.Id) .FirstOrDefaultAsync(); if (query == null || restaurant == null) { return(BadRequest()); } restaurant.RestaurantName = updateRestaurantRequest.RestaurantName; restaurant.Description = updateRestaurantRequest.Description; restaurant.RestaurantCategory = query; if (updateRestaurantRequest.RestaurantImagePath != null) { if (updateRestaurantRequest.RestaurantImagePath != null) { restaurant.RestaurantImagePath = updateRestaurantRequest.RestaurantImagePath; } } var updated = await _restaurantService .UpdateRestaurantAsync(restaurant); if (updated) { return(Ok(new Response <RestaurantResponse>(_mapper.Map <RestaurantResponse>(restaurant)))); } return(BadRequest()); }