public async Task <ActionResult <Object> > Create(PhoneBookEntryDTO data) { var user = GetCurrentUser(); if (user != null) { PhonebookEntry entry = new PhonebookEntry() { Id = Guid.NewGuid(), FirstName = data.FirstName, Surname = data.Surname, PhoneNumber = data.PhoneNumber, Kind = (Enums.EntryKindEnum)data.Kind, User = user }; try { _context.PhonebookEntries.Add(entry); _ = await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { throw ex; } } return(BadRequest()); }
public async Task <ActionResult <Object> > Update(PhoneBookEntryDTO data) { var user = GetCurrentUser(); if (user != null) { Guid.TryParse(data.Id, out Guid entryId); PhonebookEntry entry = _context.PhonebookEntries.FirstOrDefault(x => x.User.Id == user.Id && x.Id == entryId); if (entry != null) { entry.FirstName = data.FirstName; entry.Surname = data.Surname; entry.PhoneNumber = data.PhoneNumber; entry.Kind = (Enums.EntryKindEnum)data.Kind; _ = await _context.SaveChangesAsync(); return(Ok()); } } return(NotFound()); }