public async Task <bool> ExcursionCreate(ExcursionCreateInputModel model) { var validLanguageIds = new HashSet <int>(await languageServices.GetAll().Select(l => l.Id).ToListAsync()); var excursionToAdd = new Excursion() { Arrival = model.Arrival, Departure = model.Departure, LastUpdated = model.LastUpdated, TouristCapacity = model.TouristCapacity, LastUpdatedBy = model.LastUpdatedBy, EndPoint = model.EndPoint, PricePerAdult = model.Price, PricePerChild = model.ChildPrice, StartingPoint = model.StartingPoint, ExcursionTypeId = model.ExcursionTypeId }; excursionToAdd.LanguageExcursions = model .LanguageIds.Where(l => validLanguageIds.Contains(l)) .Distinct() .Select(id => new LanguageExcursion() { Excursion = excursionToAdd, LanguageId = id }) .ToList(); await context.Excursions.AddAsync(excursionToAdd); await context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> CreateExcursion() { var inputModel = new ExcursionCreateInputModel() { ExcursionTypes = await excursionServices.ExcursionTypesGetAll().ToListAsync(), Languages = await languageServices.GetAll().ToListAsync() }; return(this.View(inputModel)); }