Added endpoint to create new Contact
This commit is contained in:
@@ -39,21 +39,29 @@ public class ContactsController : ControllerBase
|
||||
try
|
||||
{
|
||||
var contacts = contactsRepo.RetrieveAll();
|
||||
var users = userRepo.RetrieveAllUsers();
|
||||
|
||||
if (contacts.Exists(c => c.PhoneNumber!.Equals(contact.PhoneNumber)) ||
|
||||
string.IsNullOrEmpty(contact.UserID))
|
||||
{
|
||||
// The Contact already exists
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
var user = new User { Id = contact.UserID };
|
||||
|
||||
if (!userRepo.Exists(user).Item1)
|
||||
if (users.Count() == 0)
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
if (contacts.Count() > 0)
|
||||
{
|
||||
if (contacts.Exists(c => c.PhoneNumber!.Equals(contact.PhoneNumber)) ||
|
||||
string.IsNullOrEmpty(contact.UserID))
|
||||
{
|
||||
// The Contact already exists
|
||||
return BadRequest(response);
|
||||
}
|
||||
}
|
||||
|
||||
if (!userRepo.Exists(contact.UserID!).Item1)
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
|
||||
contact.DateCreated = DateTime.Now;
|
||||
contactsRepo.Create(contact);
|
||||
response.Data.Add(contact);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user