/// <summary> /// Ao criar o ViewModel (apenas uma vez), é criado alguns contatos de teste e enviado para a lista /// </summary> /// <param name="contactsService"></param> public ContactsListViewModel(IContactsService contactsService) { _contactsService = contactsService; var c1 = new ContactsModel("renan", "silva"); var c2 = new ContactsModel("joao", "sub1"); var c3 = new ContactsModel("maria", "sub2"); contactsService.AddContact(c1); contactsService.AddContact(c2); contactsService.AddContact(c3); }
public async Task Consume(ConsumeContext <CustomerUpdateEvent> context) { if (context.Message.Customer != null) { var customer = JsonConvert.DeserializeObject <CustomerViewModel>(context.Message.Customer); ContactViewModel contactViewModel = new ContactViewModel() { //CustomerId = customer.CustomerId.ToString(), FirstName = customer.FirstName, LastName = customer.LastName, Gender = customer.Gender, Email = customer.Email, MobilePhone = customer.MobilePhone, HomePhone = customer.HomePhone, FacebookId = customer.FacebookId, //ContactDetailsId = customer.ContactDetailsId.ToString(), Street = customer.Addresses.ElementAt(0) != null?customer.Addresses.ElementAtOrDefault(0).Street : null, City = customer.Addresses.ElementAt(0) != null?customer.Addresses.ElementAtOrDefault(0).City : null, Province = customer.Addresses.ElementAt(0) != null?customer.Addresses.ElementAtOrDefault(0).Province : null, ZipCode = customer.Addresses.ElementAt(0) != null?customer.Addresses.ElementAtOrDefault(0).ZipCode : null }; await _contactService.AddContact(contactViewModel); } }
public void PostContact(int personID, [FromBody] ContactModel contact) { Contact contactToAdd = ModelConverter.GetContact(contact); contactToAdd.Person = new Person { PersonID = personID }; _contactsService.AddContact(contactToAdd); }
public async Task <IActionResult> CreateContact([FromBody] AddContactDto addContactDto, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _contactsService.AddContact(addContactDto, ct); return(Ok()); }
public void AddContact_Should_Add_PhoneContact_To_Database() { Person personOnDb = new Person { Name = "name" }; _personRepository.Add(personOnDb); PhoneContact contact = new PhoneContact { Person = personOnDb, Name = "home", PhoneNumber = "0000-0000" }; _contactsService.AddContact(contact); IEnumerable <Contact> contactsOnDb = _contactRepository.RetrieveAll(); contactsOnDb.Should().HaveCount(1); contactsOnDb.First().Should().BeOfType <PhoneContact>(); contactsOnDb.First().As <PhoneContact>().PhoneNumber.Should().Be(contact.PhoneNumber); contactsOnDb.First().Name.Should().Be(contact.Name); contactsOnDb.First().Person.Name.Should().Be(contact.Person.Name); }
public async Task AddContact(string email) { int userId = _auth.GetCurrentUserId(); try { Contact contact = _contactsService.AddContact(userId, email); await Clients.User($"{userId}").SendAsync("ReceiveSingleContact", contact); } catch (Exception ex) { await Clients.User($"{userId}").SendAsync("ReceiveSingleContact", null, ex); } }
public IHttpActionResult Add(ContactViewModel vm) { if (!ModelState.IsValid) { var response = ModelState.Keys.SelectMany(k => ModelState[k].Errors).Select(m => m.ErrorMessage).ToArray(); return(BadRequest(ModelState)); } var entity = vm.ToDomainObject <Contact>(); _contactsService.AddContact(entity); _contactsService.SaveContact(); var responseEntity = entity.ToBussinessObject <ContactViewModel>(); return(Created("", responseEntity)); }
public void ServiceShouldAddNewContact() { var contact = new Contact() { Name = "Test1", ContactType = ContactType.Programmer, Experience = 1, Salary = 1 }; var maxId = _contacts.Max(x => x.Id); _contactsService.AddContact(contact); Assert.That(contact, Is.EqualTo(_contacts.Last())); Assert.That(maxId + 1, Is.EqualTo(_contacts.Last().Id)); }
public async Task <IActionResult> AddContact([FromBody] ContactViewModel addedContact) { try { if (addedContact != null) { await _service.AddContact(addedContact); return(Ok("New contact Added.")); } } catch (Exception ex) { _logger.LogError($"An exception occurred while adding a new contact: {ex.Message}"); } return(BadRequest("Failed to add new contact.")); }
private async Task AddNewUser() { try { var newlyAddedContact = await NavigationService.Navigate <AddContactViewModel, ContactModel, ContactModel> (new ContactModel()); if (newlyAddedContact != null) { await ContactService.AddContact(newlyAddedContact); await LoadContacts(); } } catch (Exception ex) { ErrorHandler.OutPutErrorToConsole(ex); } }