public async Task <IActionResult> PutAddressContact([FromRoute] int id, [FromBody] AddressContact addressContact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != addressContact.Id) { return(BadRequest()); } _context.Entry(addressContact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AddressContactExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public AddressContact Remove(AddressContact addressContact) { var removedAddressContact = _addressContactContext.AddressContacts.Remove(addressContact); _addressContactContext.SaveChanges(); return(removedAddressContact); }
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)); }
public AddressContact Add(AddressContact addressContact) { var returnedAddressContact = _addressContactContext.AddressContacts.Add(addressContact); _addressContactContext.Context.SaveChanges(); return(returnedAddressContact); }
public async Task <IActionResult> PostAddressContact([FromBody] AddressContact addressContact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AddressContact.Add(addressContact); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAddressContact", new { id = addressContact.Id }, addressContact)); }
private AddressContact CreateAddressContact(CreateRegattaViewModel createRegattaViewModel) { Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.AddressContacts.AddressContact, AddressContact>()); AddressContact addressContact = Mapper.Map <AddressContact>(createRegattaViewModel.AddressContact); using (var context = new AddressContactContext()) { var service = new AddressContactService(context); service.Add(addressContact); } return(addressContact); }
public ActionResult Create(AddressContact addressContact) { try { // TODO: Add insert logic here //_service.Add(addressContact); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> OnGetAsync(int?id, int?address) { if (id == null) { return(NotFound()); } AddressId = address ?? default(int); Contact = await _context.AddressContact.FirstOrDefaultAsync(m => m.Id == id); if (Contact == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id, int?address) { if (id == null) { return(NotFound()); } AddressId = address ?? default(int); Contact = await _context.AddressContact.FindAsync(id); if (Contact != null) { _context.AddressContact.Remove(Contact); await _context.SaveChangesAsync(); } return(RedirectToPage("../Details", new { id = address })); }
public ActionResult Create(CreateClubsViewModel createClubViewModel) { if (ModelState.IsValid) { AddressContact addressContact = CreateAddressContact(createClubViewModel); Mapper.Initialize(cfg => cfg.CreateMap <PocoClasses.Clubs.PocoClub, Club>()); Club Clubs = Mapper.Map <Club>(createClubViewModel.Club); Clubs.AddressContactId = addressContact.Id; using (var context = new ClubContext()) { var service = new ClubService(context); service.Create(Clubs); } return(RedirectToAction("Index")); } return(View()); }
public AddressContact Edit(AddressContact addressContact) { var dbAddressContact = _addressContactContext.AddressContacts.SingleOrDefault(a => a.Id == addressContact.Id); if (dbAddressContact == null) { throw new Exception("Can't find address contact in db!"); } dbAddressContact.BoxNumber = addressContact.BoxNumber; dbAddressContact.StreetAddress = addressContact.StreetAddress; dbAddressContact.City = addressContact.City; dbAddressContact.ZipCode = addressContact.ZipCode; dbAddressContact.PhoneNumber = addressContact.PhoneNumber; dbAddressContact.NextOfKin = addressContact.NextOfKin; dbAddressContact.Country = addressContact.Country; _addressContactContext.SaveChanges(); return(addressContact); }