public void UpdateRestaurant(int restaurantId, RestaurantRequestDto requestDto) { var existingItem = _restaurantRepository.GetSingle(restaurantId); _mapper.Map(requestDto, existingItem.Result); var existingTags = _restaurantRepository.GetRestaurantTags(restaurantId); foreach (var tag in existingTags.Result) { _restaurantRepository.RemoveCuisineTag(tag); } foreach (int id in requestDto.CuisineTagIds) { _restaurantRepository.AddCuisineTag(new RestaurantCuisineEntity { CuisineId = id, RestaurantId = restaurantId }); } _restaurantRepository.Update(existingItem.Result); if (!_restaurantRepository.Save()) { throw new Exception("Updating a item failed on save."); } }
public void AddRestaurant(RestaurantRequestDto requestDto) { RestaurantEntity toAdd = new RestaurantEntity { Name = requestDto.Name, Address = requestDto.Address, FamilyFriendly = requestDto.FamilyFriendly, VeganOptions = requestDto.VeganOptions, Rating = requestDto.Rating }; _restaurantRepository.Add(toAdd); foreach (int id in requestDto.CuisineTagIds) { _restaurantRepository.AddCuisineTag(new RestaurantCuisineEntity { CuisineId = id, RestaurantId = toAdd.Id }); } if (!_restaurantRepository.Save()) { throw new Exception("Creating a item failed on save."); } }
public ActionResult <RestaurantRequestDto> UpdateItem(int id, [FromBody] RestaurantRequestDto updateDto) { if (updateDto == null) { return(BadRequest()); } _restaurantService.UpdateRestaurant(id, updateDto); return(Ok()); }
public ActionResult <RestaurantDto> AddItem(ApiVersion version, [FromBody] RestaurantRequestDto createDto) { try { if (createDto == null) { return(BadRequest()); } _restaurantService.AddRestaurant(createDto); return(Ok()); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async void UpdateRestaurant(int id, RestaurantRequestDto requestDto) { var request = new RestaurantDto { Id = id, Name = requestDto.Name, Address = requestDto.Address, FamilyFriendly = requestDto.FamilyFriendly, VeganOptions = requestDto.VeganOptions, Rating = requestDto.Rating, CuisineTagIds = requestDto.CuisineTagIds, Cuisine = new List <string> { "test 1", "test 3" } }; _restaurants.Remove(_restaurants.FirstOrDefault(r => r.Id == id)); _restaurants.Add(request); }
public async void AddRestaurant(RestaurantRequestDto requestDto) { await Task.Delay(200); var request = new RestaurantDto { Id = 4, Name = requestDto.Name, Address = requestDto.Address, FamilyFriendly = requestDto.FamilyFriendly, VeganOptions = requestDto.VeganOptions, Rating = requestDto.Rating, CuisineTagIds = requestDto.CuisineTagIds, Cuisine = new List <string> { "test 1", "test 3" } }; _restaurants.Add(request); }