public async Task <ActionResult> PostEntry(Guid phonebookId, [FromBody] PhonebookEntryDTO entry) { if (!ModelState.IsValid) { BadRequest(ModelState); } var phonebook = await phonebookRepository.GetById(phonebookId); if (phonebook == null) { return(NotFound()); } var phonebookEntry = PhonebookEntryFactory.Create(phonebook); phonebookEntry.Name = entry.Name; phonebookEntry.PhoneNumber = entry.PhoneNumber; //.NET returned empty Guid from JSON request //TO DO : Use Automapper phonebookEntryRepository.Add(phonebookEntry); await phonebookEntryRepository.Commit(); return(Ok()); }
private PhonebookEntry CreateEntry(Domain.Entities.Phonebook phonebook, string name, string number) { var entry = PhonebookEntryFactory.Create(phonebook); entry.Name = name; entry.PhoneNumber = number; return(entry); }
public async Task <IActionResult> PutEntry(Guid phonebookId, [FromBody] PhonebookEntryDTO entry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var phonebook = await phonebookRepository.GetById(phonebookId); if (phonebook == null) { NotFound(); } var phonebookEntry = PhonebookEntryFactory.Create(phonebook); entry.SetIds(phonebookEntry); phonebookEntry.Name = entry.Name; phonebookEntry.PhoneNumber = entry.PhoneNumber; phonebookEntryRepository.Update(phonebookEntry); await phonebookEntryRepository.Commit(); return(Ok()); }