public async Task CreateAsync(ContactDto contactDto) { var contact = await _contactManager.CreateAsync(contactDto.Name, contactDto.DateOfBirth, contactDto.Address); foreach (var contactPhone in contactDto.Phones) { contact.AddPhone(contactPhone.PhoneNumber); } await _contactRepository.InsertAsync(contact); await _unitOfWork.CommitAsync(); }
public async Task <IActionResult> CreateAsync([FromBody] ResourceRequest <ContactRequestDto> resource) { if (resource.Data.Type != "contacts") { return(StatusCode(409)); } var contact = _mapper.Map <Contact>(resource.Data); contact = await _contactManager.CreateAsync(contact); var contactDto = _mapper.Map <ContactDto>(contact); var links = _jsonApiBuilder.BuildNewSingleResourceLinks(HttpContext.Request.Path, contactDto.Id); return(Created(links.Self, new ResourceResponse() { Links = links, Data = contactDto })); }
public async Task <ActionResult <ResponseModel <ContactModel> > > CreateClientContactAsync([FromBody] ContactInputModel inputModel, int id) { var contact = await _contactManager.CreateAsync( inputModel.FirstName, inputModel.LastName, inputModel.Email, inputModel.Phone, id, CurrentUser.Id ); if (contact != null) { return(Ok(new ResponseModel <ContactModel>(new ContactModel(contact)))); } else { return(BadRequest(new ErrorModel("Unable to create a Contact for this Client."))); } }
public IActionResult Create([FromBody] Contact value) { return(new WebApiPost <Contact>(this, () => _manager.CreateAsync(WebApiActionBase.Value(value)), operationType: OperationType.Create, statusCode: HttpStatusCode.Created, alternateStatusCode: null)); }