public ActionResult Create(CreateRegattaViewModel createRegattaViewModel) { if (ModelState.IsValid) { AddressContact addressContact = CreateAddressContact(createRegattaViewModel); ContactPerson contactPerson = CreateContactPerson(createRegattaViewModel); Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.Regattas.Regatta, Regatta>()); Regatta regatta = Mapper.Map <Regatta>(createRegattaViewModel.Regatta); regatta.AddressContactId = addressContact.Id; regatta.ContactPersonsId = contactPerson.Id; regatta.HostingClubId = FindClubId(); using (var context = new RegattaContext()) { var service = new RegattaService(context); service.Add(regatta); } ViewBag.AddressContactId = new SelectList(new AddressContactContext().AddressContacts, "Id", "NextOfKin", regatta.AddressContactId); // ViewBag.AddressContactId = new SelectList(new AddressContactService(new AddressContactContext()).GetAll(),"Id","NextOfKin",regatta.AddressContactId); // ViewBag.HostingClubId = new SelectList(new ClubService(new ClubContext()).GetAll(), "Id", "Name", regatta.HostingClubId); // ViewBag.ContactPersonsId = new SelectList(new ContactPersonService(new ContactPersonContext()).GetAll(), "Id", "Email", regatta.ContactPersonsId); return(RedirectToAction("Index")); } return(View(createRegattaViewModel)); }
private List <Regatta> GetAllRegattas() { using (var context = new RegattaContext()) { var service = new RegattaService(context); var regattas = service.GetAll(); return(regattas.ToList()); } }
public RegattaService(RegattaContext regattaContext) { _regattaContext = regattaContext; }