public async Task <Tourist> SaveTouristModel(NewTouristForm model) { foreach (var t in model.Tours) { if (model.SelectedTourIds.Contains(t.TourId)) { t.selected = true; } } Tourist tourist = new Tourist(); tourist.Fullname = model.Fullname; tourist.Hometown = model.Hometown; tourist.GuideId = model.GuideId; tourist.Age = model.Age; tourist.Avatar = model.Path; List <TouristTour> touristTours = new List <TouristTour>(); await db.Tourists.AddAsync(tourist); // сохраняем в бд все изменения await db.SaveChangesAsync(); foreach (var t in model.Tours.Where(x => x.selected == true)) { TouristTour touristTour = new TouristTour(); touristTour.TouristId = tourist.Touristid; touristTour.TourId = t.TourId; touristTours.Add(touristTour); } await db.TouristTour.AddRangeAsync(touristTours); await db.SaveChangesAsync(); return(tourist); }
public async Task ProcessNewTouristModel(NewTouristForm model) { if (model.Avatar != null) { model.Path = await model.Avatar.PathReturn(_appEnvironment); } List <int> tours = model.Tours.Where(x => x.selected == true).Select(x => x.TourId).ToList(); model.SelectedTourIds = tours; }
public async Task <ActionResult> SaveNewTourist(NewTouristForm model) { var result = await _touristServ.SaveTouristModel(model); string message = "Saving of new tourist"; var logger = _loggerCreator.FactoryMethod(); logger.LoggMessage(this.GetType().Name, message); return(RedirectToAction("TouristsOfCurrentGuideForm", "Tourist", new { id = result.GuideId })); }
public async Task <ActionResult> AddTouristFormStep2(NewTouristForm model) { await _touristServ.ProcessNewTouristModel(model); string message = "Submition of new tourist form"; var logger = _loggerCreator.FactoryMethod(); logger.LoggMessage(this.GetType().Name, message); return(View(model)); }
public async Task <NewTouristForm> CreateNewTouristForm() { NewTouristForm model = new NewTouristForm(); model.Guides = await db.Guides.ToListAsync(); model.Tours = await db.Tours.ToListAsync(); model.selectListg = new SelectList(model.Guides, "GuideId", "Name"); model.selectListt = new MultiSelectList(model.Tours, "TourId", "Name"); return(model); }
public async Task <ActionResult> AddTouristFormStep1(NewTouristForm model) { await _touristServ.ProcessNewTouristModel(model); string message = "Upload new tourist form to submition"; var logger = _loggerCreator.FactoryMethod(); logger.LoggMessage(this.GetType().Name, message); if (ModelState.IsValid) { return(RedirectToAction("AddTouristFormStep2", model)); } return(View(model)); }
public async Task ProcessEnteredTouristModel(NewTouristForm model) { model.Tours = await db.Tours.ToListAsync(); foreach (var t in model.Tours) { if (model.SelectedTourIds.Contains(t.TourId)) { t.selected = true; } } model.Guides = await db.Guides.ToListAsync(); model.selectListg = new SelectList(model.Guides, "GuideId", "Name"); var selectedGuideItem = model.selectListg.First(x => x.Value == model.GuideId.ToString()); selectedGuideItem.Selected = true; }