//GET //get all the details as per restaurant Id : user public async Task <AllDetails> GetRestaurantDetails(int id) { var eatery = await _dataRepository.Where <Restaurant>(r => r.ID == id).Include(l => l.Location).FirstAsync(); var reviews = await _dataRepository.Where <Review>(r => r.Restaurant.ID == id).Include(u => u.User).ToListAsync(); var comments = await _dataRepository.GetAll <Comment>().Include(c => c.User).ToListAsync(); //reviews var reviewsAC = new List <ReviewsAC>(); _mapper.Map(reviews, reviewsAC); //comments var commentACs = new List <CommentAC>(); List <CommentAC> comment = new List <CommentAC>(); foreach (var item in reviewsAC) { var allComments = comments.Where(k => k.ReviewID == item.ReviewId).ToList(); _mapper.Map(allComments, commentACs); comment.AddRange(commentACs); } //adding every detail to AllDetails class var details = new AllDetails { RestaurantID = id, LocationID = eatery.ID, Locations = eatery.Location, RestaurantName = eatery.RestaurantName, Description = eatery.Description, ContactNumber = eatery.ContactNumber, CuisineType = eatery.CuisineType, AverageCost = eatery.AverageCost, OpeningHours = eatery.OpeningHours, MoreInfo = eatery.MoreInfo, Reviews = reviewsAC, Comments = comment }; //location var allCity = new AllCity(); var allCountry = new AllCountry(); _mapper.Map(await _dataRepository.Where <City>(c => c.ID == eatery.Location.FirstOrDefault().CityID).FirstAsync(), allCity); _mapper.Map(await _dataRepository.Where <Country>(c => c.ID == eatery.Location.FirstOrDefault().CountryID).FirstAsync(), allCountry); details.City = allCity; details.Country = allCountry; return(details); }
//________________________________________________________________________________________________________________________________ //update restaurant details(dishes/ location) : admin public async Task <AllDetails> EditRestaurant(int id, AllDetails details) { City city = new City(); _mapper.Map(details.City, city); _dataRepository.Entry(city); Country country = new Country(); _mapper.Map(details.Country, country); _dataRepository.Entry(country); Location location = new Location(); _mapper.Map(details, location); Restaurant restaurants = new Restaurant(); _mapper.Map(details, restaurants); restaurants.ID = id; ICollection <Location> Location = new List <Location>(); Location.Add(location); ICollection <Dishes> Dishes = new List <Dishes>(); restaurants.Location = Location; restaurants.Dishes = Dishes; _dataRepository.Entry(location); _dataRepository.Entry(restaurants); await _dataRepository.SaveChangesAsync(); return(details); }
//post all restaurants public async Task <AllDetails> AddAllRestaurants(AllDetails details) { City city = new City(); _mapper.Map(details.City, city); await _dataRepository.AddAsync <City>(city); Country country = new Country(); _mapper.Map(details.Country, country); await _dataRepository.AddAsync <Country>(country); Location location = new Location(); _mapper.Map(details, location); await _dataRepository.AddAsync <Location>(location); Restaurant restaurant = new Restaurant(); _mapper.Map(details, restaurant); await _dataRepository.AddAsync <Restaurant>(restaurant); ICollection <Location> Locations = new List <Location>(); Locations.Add(location); ICollection <Dishes> Dishes = new List <Dishes>(); restaurant.Location = Locations; restaurant.Dishes = Dishes; await _dataRepository.AddAsync <Location>(location); await _dataRepository.SaveChangesAsync(); return(details); }
public async Task <ActionResult> PostAllRestaurantAsync(AllDetails restaurants) { return(Ok(await unitOfWork.Restaurant.AddAllRestaurants(restaurants))); }
public async Task <ActionResult> EditRestaurant([FromRoute] int id, [FromBody] AllDetails details) { await unitOfWork.Restaurant.EditRestaurant(id, details); return(Ok()); }
public async Task EditRestaurant_VerifyWhetherArestaurantCanBeEditedOrNot() { List <Restaurant> restaurants = new List <Restaurant> { new Restaurant { ID = 3, Dishes = new List <Dishes> { new Dishes { ID = 1, DishesName = "Burger", Costs = 200 } } }, }; List <City> cities = new List <City> { new City { ID = 1, CityName = "Kolkata" } }; List <Country> countries = new List <Country> { new Country { ID = 1, CountryName = "India" } }; List <Location> locations = new List <Location> { new Location { ID = 1, CityID = 2, CountryID = 1, Locality = "Manjalpur", City = new City { ID = 1, CityName = "Kolkata" }, Country = new Country { ID = 1, CountryName = "India" } } }; AllDetails allDetailsUpdated = new AllDetails { LocationID = 1, RestaurantID = 2, RestaurantName = "Domino's", ContactNumber = "68886888", CuisineType = "Italian", AverageCost = "500", OpeningHours = "10AM - 11PM", MoreInfo = "Pet friendly", Locations = new List <Location> { new Location { ID = 1, CityID = 2, CountryID = 1, Locality = "Manjalpur", City = new City { ID = 1, CityName = "Kolkata" }, Country = new Country { ID = 1, CountryName = "India" } } } }; _dataRepository.Setup(s => s.Entry(It.IsAny <Expression <Func <City, bool> > >())); _dataRepository.Setup(s => s.Entry(It.IsAny <Expression <Func <Country, bool> > >())); _dataRepository.Setup(s => s.Entry(It.IsAny <Expression <Func <Location, bool> > >())); _dataRepository.Setup(s => s.Entry(It.IsAny <Expression <Func <Restaurant, bool> > >())); //_dataRepository.Setup(s => s.SaveChangesAsync()); await _unitOfWorkRepository.Restaurant.EditRestaurant(1, allDetailsUpdated); //_dataRepository.Verify(v => v.AddAsync(It.IsAny<CommentAC>()), Times.Once); _dataRepository.Verify(v => v.SaveChangesAsync()); }
public async Task AddAllRestaurants_VerifyAdditionOfRestaurantsWithDetails() { AllDetails allDetails = new AllDetails { LocationID = 1, RestaurantID = 2, RestaurantName = "Domino's", ContactNumber = "68886888", CuisineType = "Italian", AverageCost = "500", OpeningHours = "10AM - 11PM", MoreInfo = "Pet friendly", Locations = new List <Location> { new Location { ID = 1, CityID = 2, CountryID = 1, Locality = "Manjalpur", City = new City { ID = 1, CityName = "Kolkata" }, Country = new Country { ID = 1, CountryName = "India" } } }, Reviews = new List <ReviewsAC> { new ReviewsAC { userID = "dcbe1262-4be8-493a-8821-f4d52778d878", UserName = "******", LikesCount = 4, ReviewId = 1007, ReviewTexts = "erjk", commentACs = new List <CommentAC> { new CommentAC { ID = 1, UserID = "dcbe1262-4be8-493a-8821-f4d52778d878", FullName = "Nina Dobrev", CommentMessage = "good", ReviewID = 2 } } } }, Comments = new List <CommentAC> { new CommentAC { ID = 1, UserID = "dcbe1262-4be8-493a-8821-f4d52778d878", FullName = "Nina Dobrev", CommentMessage = "good", ReviewID = 2 } } }; _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <Restaurant, bool> > >()));//.Returns(restaurant.AsQueryable().BuildMock().Object); _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <City, bool> > >())); _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <Country, bool> > >())); _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <Location, bool> > >())); _dataRepository.Setup(s => s.SaveChangesAsync()); await _unitOfWorkRepository.Restaurant.AddAllRestaurants(allDetails); _dataRepository.Verify(v => v.AddAsync(It.IsAny <Dishes>()), Times.Once); _dataRepository.Verify(v => v.SaveChangesAsync()); }