public async Task <IActionResult> CreateTag(int contactId, DetailInfoForUpdateDto details) { Tag tag = new Tag(); int tagIdFromRepo = await _contactTagRepo.getTagId(details.tagName); if (tagIdFromRepo == -1) { tag.TagName = details.tagName; _tagsRepo.Add(tag); _contactTagRepo.Add(new ContactTag { TagId = tag.Id, ContactId = contactId }); await _tagsRepo.SaveAll(); await _contactTagRepo.SaveAll(); } else { var tagsFromRepo = await _contactTagRepo.GetTags(contactId); if (tagsFromRepo.Any(t => t.TagName == details.tagName)) { return(BadRequest()); } else { _contactTagRepo.Add(new ContactTag { TagId = tagIdFromRepo, ContactId = contactId }); await _contactTagRepo.SaveAll(); } } return(Ok()); }
public async Task <IActionResult> UpdateContact(int contactId, int numberId, DetailInfoForUpdateDto numberForUpdateDto) { var number = await _repo.GetNumber(contactId, numberId); number.PhoneNumber = numberForUpdateDto.PhoneNumber; if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating Number with {contactId} failed on save"); }
public async Task <IActionResult> CreateNumber(int contactId, DetailInfoForUpdateDto details) { Number number = new Number(); number.PhoneNumber = details.PhoneNumber; number.ContactId = contactId; _repo.Add(number); await _repo.SaveAll(); return(Ok()); }
public async Task <IActionResult> UpdateContact(int contactId, int emailId, DetailInfoForUpdateDto emailForUpdateDto) { var email = await _repo.GetEmail(contactId, emailId); email.EmailAddress = emailForUpdateDto.emailAddress; if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating Email with {contactId} failed on save"); }
public async Task <IActionResult> CreateEmail(int contactId, DetailInfoForUpdateDto details) { Email email = new Email(); email.EmailAddress = details.emailAddress; email.ContactId = contactId; _repo.Add(email); await _repo.SaveAll(); return(Ok()); }
public async Task <IActionResult> UpdateTag(int contactId, int tagId, DetailInfoForUpdateDto detailInfoForUpdateDto) { var tag = await _tagsRepo.GetTag(contactId, tagId); if ((await _contactTagRepo.GetNumberOfContactsForTag(tagId)) == 1) { tag.TagName = detailInfoForUpdateDto.tagName; if (await _tagsRepo.SaveAll()) { return(NoContent()); } } else { _contactTagRepo.Delete(new ContactTag { TagId = tagId, ContactId = contactId }); var tagIdFromRepo = await _contactTagRepo.getTagId(detailInfoForUpdateDto.tagName); if (tagIdFromRepo >= 0) { _contactTagRepo.Update(new ContactTag { ContactId = contactId, TagId = tagIdFromRepo }); } else { await CreateTag(contactId, detailInfoForUpdateDto); } await _tagsRepo.SaveAll(); await _contactTagRepo.SaveAll(); return(NoContent()); } throw new Exception($"Updating Tag with {tagId} failed on save"); }