public async Task RegisterAsync(RestaurantOnCreateDto restaurantDto) { var restaurantToRegister = new Restaurant(restaurantDto.Name, restaurantDto.Description, restaurantDto.Cuisine, restaurantDto.RepresentativePhotoUrl, restaurantDto.Localization, restaurantDto.Tables); await _restaurantRepository.AddAsync(restaurantToRegister); }
public async Task <bool> AddAsync(RestaurantViewModel model) { var restaurant = new Restaurant { RestaurantId = Guid.NewGuid(), Name = model.Name }; return(await _restaurantRepository.AddAsync(restaurant)); }
public async Task <IActionResult> OnPost() { Message = string.Empty; if (ModelState.IsValid) { if (RestaurantDto.Id != Guid.Empty) { var fetchedRestaurant = await _restaurantRepository.GetByIdAsync(id : RestaurantDto.Id); fetchedRestaurant.SetName(RestaurantDto.Name); fetchedRestaurant.SetLocation(RestaurantDto.Location); fetchedRestaurant.SetCuisineType(RestaurantDto.CuisineType); var updatedRestaurant = await _restaurantRepository.UpdateAsync(fetchedRestaurant); if (updatedRestaurant == null) { Message = "Fail to update Restaurant! Please try again."; } else { TempData["Message"] = "Restaurant updated!"; return(RedirectToPage("./Detail", new { restaurantId = updatedRestaurant.Id })); } } else { var newRestaurant = new Restaurant(name: RestaurantDto.Name, location: RestaurantDto.Location, cuisineType: RestaurantDto.CuisineType); var createdRestaurant = await _restaurantRepository.AddAsync(newRestaurant); if (createdRestaurant == null) { Message = "Fail to create new Restaurant! Please try again."; } else { TempData["Message"] = "Restaurant created!"; return(RedirectToPage("./Detail", new { restaurantId = createdRestaurant.Id })); } } } Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>(); return(Page()); }
public async Task <RestaurantResponse> SaveAsync(Restaurant Restaurant) { try { await _restaurantRepository.AddAsync(Restaurant); return(new RestaurantResponse(Restaurant)); } catch (Exception ex) { return(new RestaurantResponse($"An error ocurred while saving the Restaurant: {ex.Message}")); } }
public async Task <BaseResponse> AddAsync(AddRestaurantRequest request) { var restaurant = _mapper.Map <AddRestaurantRequest, Restaurant>(request); var loggedUser = (User)_httpContext.Items.GetOrDefault("User"); restaurant.CreatedById = loggedUser.Id; await _restaurantRepository.AddAsync(restaurant); await _unitOfWork.SaveChangesAsync(); return(new BaseResponse()); }
public async Task <IActionResult> PostRestaurant([FromBody] Restaurant restaurant) { if (!ModelState.IsValid) { return(this.ErrorResult("", "HttpPost data is not valid!", HttpStatusCode.BadRequest)); } Restaurant createdRestaurant = await _restaurantRepository.AddAsync(restaurant); if (createdRestaurant == null) { return(this.ErrorResult("", "Fail to create restaurant!")); } return(CreatedAtAction(nameof(GetRestaurant), new { id = createdRestaurant.Id })); }
public async Task <Restaurant> CreateRestaurantAsync(long cityId, CreateRestaurantRq createRestaurant) { var city = await _cityRepository.GetByIdAsync(cityId); if (city == null) { throw new ApplicationNotFoundException($"Could not found {nameof(City)} with id '{cityId}'"); } var restaurant = _mapper.Map <Restaurant>(createRestaurant); var newRestaurant = await _restaurantRepository.AddAsync(restaurant); var junction = new CityRestaurantJunction { CityId = city.Id.Value, RestaurantId = newRestaurant.Id.Value }; var newRestaurants = await _restaurantRepository.AddCityRestaurantJunction(junction); return(newRestaurant); }
public async Task AddRestaurant(Restaurant restaurant) { await _repository.AddAsync(restaurant); }
public async Task HandleAsync(CreateRestaurant command) { var newRestaurant = new Restaurant(command.Name, command.Address, command.City, command.State); await _repository.AddAsync(newRestaurant); }
public async Task AddAsync(Guid id, string name, string cuisine, string address, IEnumerable <object> menu, DateTime createdDate) { var restaurant = new Restaurant(id, name, cuisine, address, createdDate); await _restaurantRepository.AddAsync(restaurant); }