public IActionResult UpdateRestaurant([FromRoute] long id, [FromBody] UpdateRestaurantRequest updateRestaurant)
        {
            addUpdateRequestValidator.ValidateAndThrow(updateRestaurant);
            var restaurant = restaurantRepository.UpdateRestaurant(id, updateRestaurant);

            return(Ok(restaurant));
        }
Ejemplo n.º 2
0
 public static RestaurantEntity ToEntity(this UpdateRestaurantRequest restaurant)
 {
     return(new RestaurantEntity
     {
         Id = restaurant.Id,
         Name = restaurant.Name,
         Address = restaurant.Address
     });
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public async Task UpdateRestaurant(UpdateRestaurantRequest restaurantRequest)
 {
     await repository.UpdateRestaurant(restaurantRequest.ToEntity());
 }
Ejemplo n.º 5
0
 public ActionResult Update([FromRoute] int id, [FromBody] UpdateRestaurantRequest request)
 {
     _restaurantService.Update(id, request);
     return(NoContent());
 }
Ejemplo n.º 6
0
        public async Task UpdateRestaurant(UpdateRestaurantRequest restaurantRequest)
        {
            await restaurantValidatorFactory.CreateUpdateRestaurantValidator().ThrowIfNotValid(restaurantRequest);

            await restaurantService.UpdateRestaurant(restaurantRequest);
        }
Ejemplo n.º 7
0
        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());
        }