public void InsertData() { Console.WriteLine(new string('*', 20)); Console.WriteLine("Enter the FirstName, LastName , Company And Title Of Contacts"); Console.Write("First Name : "); String fName = Console.ReadLine(); Console.Write("Last Name : "); String lName = Console.ReadLine(); Console.Write("Company Name : "); String company = Console.ReadLine(); Console.Write("Title Name : "); String title = Console.ReadLine(); //inserting Contacts contacts1 = new Contacts { FirstName = fName, LastName = lName, Company = company, Title = title }; contactsRepository.Add(contacts1); ShowData(); }
public IActionResult AddPerson([FromBody] Person person) { if (person.Id < 0 || string.IsNullOrWhiteSpace(person.FirstName) || string.IsNullOrWhiteSpace(person.LastName) || string.IsNullOrWhiteSpace(person.Email)) { return(BadRequest("Invalid input (e.g. required field missing or empty)")); } repository.Add(person); return(Created(nameof(AddPerson), person)); }
public HttpResponseMessage PostContact(Contact item) { var response = new HttpResponseMessage(); var dupStatus = repository.CheckDuplicates(item); if (dupStatus == 0) { if (repository.Add(item)) { response = Request.CreateResponse <Contact>(HttpStatusCode.Created, item); string uri = Url.Link("DefaultApi", new { id = item.Id }); response.Headers.Location = new Uri(uri); } else { response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Internal server error occurred. Could not save data."), ReasonPhrase = "Error" }; throw new HttpResponseException(response); } return(response); } else if (dupStatus == 1 || dupStatus == 2) { string message = ""; if (dupStatus == 1) { message = "Email already exists!"; } else if (dupStatus == 2) { message = "Phone no already exists"; } response = new HttpResponseMessage(HttpStatusCode.Conflict) { Content = new StringContent(message), ReasonPhrase = "Error" }; throw new HttpResponseException(response); } else { response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Internal server error occurred. Could not save data."), ReasonPhrase = "Error" }; throw new HttpResponseException(response); } }
public async Task <IActionResult> Create([FromBody] Contacts item) { if (item == null) { return(BadRequest()); } await _repo.Add(item); return(CreatedAtRoute("GetContacts", new { Controller = "Contacts", id = item.MobilePhone }, item)); }
public IActionResult AddPerson([FromBody] Person person) { if (person.Email is null) { return(BadRequest()); } repo.Add(person); return(Created(nameof(GetById), person)); }
public IActionResult AddPerson([Required, FromBody] Contact newPerson) { if (newPerson.Id < 1) { return(BadRequest("Invalid id")); } if (newPerson.Email == null || newPerson.Email.Length == 0) { return(BadRequest($"Required field {nameof(newPerson.Email)} empty or missing")); } repository.Add(newPerson); return(CreatedAtAction(nameof(DeletePerson), new { id = newPerson.Id }, newPerson)); }
public async Task <IActionResult> AddContact(ContactDtoForAdd contactNew) { var contact = new Contact(); contact.Name = contactNew.Name; contact.Surname = contactNew.Surname; contact.DateOfBirth = contactNew.DateOfBirth; contact.Address = new Address(); contact.Address.Street = contactNew.Address.Street; contact.Address.AddressNumber = contactNew.Address.AddressNumber; contact.Address.Postcode = contactNew.Address.Postcode; contact.Address.City = contactNew.Address.City; contact.Address.Country = contactNew.Address.Country; contact.ContactData = new List <ContactData>(); foreach (ContactDataDto contactData in contactNew.ContactData) { ContactData contactDataNew = new ContactData(); contactDataNew.ContactDataStatus = "Y"; contactDataNew.ContactDataType = contactData.ContactDataType; contactDataNew.ContactDataValue = contactData.ContactDataValue; contact.ContactData.Add(contactDataNew); } contactsRepository.Add(contact); if (await contactsRepository.SaveAll()) { return(NoContent()); } return(BadRequest("Error occured during adding of a contact!")); }
public ContactDTO Add(ContactDTO Model) { ContactEntity entity = new ContactEntity { Address = Model.Address, Name = Model.Name, Notes = Model.Notes, Phone = Model.Phone, }; contactsRepository.Add(entity); contactsRepository.SaveDbChanges(); Model.Id = entity.Id; return(Model); }
public bool AddContact(Contacts contactToAdd) { if (!ValidateContact(contactToAdd)) { return(false); } else { // Database logic //try //{ _repository.Add(contactToAdd); _repository.Commit(); //catch //{ // return false; //} return(true); } }
public void Add(Contact contact) { _contactsRepository.Add(contact); }
public RedirectToActionResult Create(Contact contact) { var newContact = _contactsRepository.Add(contact); return(RedirectToAction("details", new { id = newContact.ContactId })); }