Esempio n. 1
0
        public int AddContact(ContactDTO contactDto)
        {
            Contact contact = mapper.ToEntity(contactDto);

            contact.SessionID = Guid.NewGuid().ToString();
            return(_contactDAL.AddContact(contact));
        }
Esempio n. 2
0
        public ContactModel Update(ContactModel contactModel)
        {
            var contact = _contactRepository.GetById(contactModel.Id);

            if (contact == null)
            {
                throw new NotFoundException(Messages.ContactNotFound);
            }

            var contactWithName = _contactRepository.GetByName(contactModel.Name);

            if (contactWithName != null && contact.Id != contactWithName.Id)
            {
                throw new ValidationException(Messages.AContactWithThatNameAlreadyExists);
            }

            var contactWithPrefixAndNumber =
                _contactRepository.GetByPrefixAndNumber(contactModel.NumberPrefix.Id, contactModel.Number);

            if (contactWithPrefixAndNumber != null && contact.Id != contactWithPrefixAndNumber.Id)
            {
                throw new ValidationException(Messages.AContactWithThatNumberAlreadyExists);
            }

            _contactRepository.Update(ContactMapper.ToEntity(contactModel));

            return(contactModel);
        }
Esempio n. 3
0
        public async Task <ContactModel> AddAsync(ContactModel contactModel)
        {
            var contactWithName = await _contactRepository.GetByNameAsync(contactModel.Name);

            if (contactWithName != null)
            {
                throw new ValidationException(Messages.AContactWithThatNameAlreadyExists);
            }

            var contactWithPrefixAndNumber =
                await _contactRepository.GetByPrefixAndNumberAsync(contactModel.NumberPrefix.Id, contactModel.Number);

            if (contactWithPrefixAndNumber != null)
            {
                throw new ValidationException(Messages.AContactWithThatNumberAlreadyExists);
            }

            var id = await _contactRepository.AddAsync(ContactMapper.ToEntity(contactModel));

            contactModel.Id = id;

            return(contactModel);
        }