public ActionResult <ContactModel> CreateContact(ContactForManipulationModel contact) { var contactEntity = _mapper.Map <Entities.Contact>(contact); _contactsRepository.AddContact(contactEntity); _contactsRepository.Save(); var contactToReturn = _mapper.Map <ContactModel>(contactEntity); return(CreatedAtRoute("GetContact", new { contactId = contactToReturn.Id }, contactToReturn)); }
public async Task <IActionResult> AddContact(ContactToAddDTO contactToAddDTO) { if (await _contactRepo.ContactExists(contactToAddDTO.Name)) { return(BadRequest("Contact already exists")); } var phoneNumberList = new List <PhoneNumber>(); foreach (var phoneNumber in contactToAddDTO.PhoneNumbers) { phoneNumberList.Add(new PhoneNumber() { Number = phoneNumber }); } var contactToAdd = new Contact { Name = contactToAddDTO.Name, Email = contactToAddDTO.Email, PhoneNumbers = phoneNumberList }; var createdContact = await _contactRepo.AddContact(contactToAdd); return(Ok(createdContact)); }
public async Task <ActionResult> Post([FromBody] Contact contact) { await _repo.AddContact(contact); var uri = $"http://localhost:5000/api/v1/contactos/{contact.ContactId}"; return(Created(uri, contact)); }
public JsonResult Create(ContactViewModel contactViewModel) { if (!ModelState.IsValid) { return(Json(new { success = false })); } var contact = _contactsRepository.AddContact(contactViewModel.ToModel()); return(Json(new { success = true, contact = contact.ToViewModel() })); }
private void OnSave() { UpdateStudent(Student, _editingStudent); //Update Student Table if (EditMode) { _studentsRepository.UpdateStudent(_editingStudent); } else { _studentsRepository.AddStudent(_editingStudent); } //Update Contacts foreach (Contact contact in AddedContacts) { _contactsRepository.AddContact(contact); } foreach (Contact contact in DeletedContacts) { _contactsRepository.DeleteContact(contact.ContactID); } //Update Biometrics foreach (RelBiometric relBiometric in AddedRelBiometrics) { _relBiometricsRepository.AddRelBiometric(relBiometric); } foreach (Biometric biometric in DeletedBiometrics) { _relBiometricsRepository.DeleteRelBiometric(biometric.FingerID); _biometricsRepository.DeleteBiometric(biometric.FingerID); } //Update Groups #region Not used foreach (RelOrganization group in AddedGroups) { _relOrganizationsRepository.AddRelOrganization(group); } foreach (RelOrganization group in DeletedGroups) { _relOrganizationsRepository.DeleteRelOrganization(group.RelOrganizationID); } #endregion SelectedImage = null; Done(); }
//POST api/contacts public HttpResponseMessage Post([FromBody] Contact contact) { try { BaseResponse <bool> response = new BaseResponse <bool>(); response.Data = _contactRepository.AddContact(contact); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { BaseResponse <BasicError> response = new BaseResponse <BasicError>(); response.Errors = new BasicError(ErrorCodes.TechnicalError.ToString(), ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
public async Task <BaseResponse> SendInvitationAsync(string userId, string invitedUserName) { if (invitedUserName == null) { return(new ErrorResponse(new ArgumentNullException($"{nameof(invitedUserName)} cannot be null!"))); } var invitedUserResponse = await _userService.GetUser(invitedUserName); var invitedUser = (invitedUserResponse as SuccessResponse <ApplicationUser>)?.Result; if (invitedUser == null) { return(invitedUserResponse); } if (invitedUser.Id == userId) { return(new ErrorResponse(new ApplicationException("Cannot send invitation to itself!"))); } var myContactsResponse = GetPotentionalContacts(userId, invitedUserName); var myContacts = (myContactsResponse as SuccessResponse <List <Contact> >)?.Result; if (myContacts == null) { return(myContactsResponse); } if (myContacts.All(c => c.UserName != invitedUserName)) { return(new ErrorResponse(new ApplicationException("Contact already exists!"))); } var newContact = new Data.Models.Contact { CreateDate = DateTimeOffset.UtcNow, RequestedById = userId, RequestedToId = invitedUser.Id, Status = Data.Models.InvitationStatuses.PendingAcceptance }; _contactsRepository.AddContact(newContact); var result = LocalMapper.Map <Contact>(newContact); return(new SuccessResponse <Contact>(result)); }
public async Task <IActionResult> AddContact([FromBody] Contacts model) { if (ModelState.IsValid) { try { var Id = await contactsRepository.AddContact(model); if (Id > 0) { return(Ok(Id)); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public void AddContact(Contact contact) { _contactsRepository.AddContact(contact); }
public void WriteContactForSpecifiedItem(ContactDto contactDto) { _commonRepo.AddContact(_mapper.Map <ContactDto, Contact>(contactDto)); }
public async Task <bool> AddContact(ContactViewModel model) { return(await _webSiteRepository.AddContact(model)); }
public void AddContact(Item contact) { cache.AddContact(contact); SubmitChanges(); }
public async Task <ActionResult> AddSave(PhoneContactModel phoneContact) { await _contactsRepository.AddContact(phoneContact); return(RedirectToAction("Index")); }