예제 #1
0
        public async Task <Contact> CreateContactAsync(Company company)
        {
            var contact = await _contactRepository.AddAsync(new Contact(Guid.NewGuid(), new List <string> {
                company.Name
            }, company.Addresses, company.Phones));

            await _contactRepository.UnitOfWork.SaveChangesAsync();

            return(contact);
        }
예제 #2
0
        public async Task <ContactDetailsDto> AddAsync(ContactCreateDto contactDto)
        {
            try
            {
                if (contactDto == null)
                {
                    throw new ArgumentNullException(nameof(contactDto));
                }

                if (await _contactRepository.FindAsync(contactDto.Name, contactDto.Address) != null)
                {
                    throw new Exception($"Contact cu name {contactDto.Name} and address {contactDto.Address} already exists.");
                }

                var contact = new Contact(contactDto);
                await _contactRepository.AddAsync(contact);

                return(_mapper.Map <ContactDetailsDto>(contact));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }
예제 #3
0
        public async Task <APIResponse <Contact> > AddContact(ContactInput input)
        {
            Contact contact = new Contact
            {
                Address     = input.Address,
                Email       = input.Email,
                Name        = input.Name,
                Phone       = input.Phone,
                MobilePhone = input.MobilePhone
            };

            Contact IsExist = await _contactRepo.GetAsync(x => x.Name == contact.Name);

            if (IsExist != null)
            {
                return new APIResponse <Contact>()
                       {
                           Code = "400", Data = null, Message = "There is already contact with the same name!", OK = false
                       }
            }
            ;

            Contact newContact = await _contactRepo.AddAsync(contact);

            return(new APIResponse <Contact>()
            {
                Code = "200", Data = newContact, Message = "Success", OK = true
            });
        }
예제 #4
0
        public async Task <Models.Result <Models.Contact> > CreateContact(Models.ContactCreate contactCreate)
        {
            var result = new Models.Result <Models.Contact>();

            try
            {
                //check Contact with same Email does not already exist
                var checkEmailEntity = await _contactRepository.GetSingleAsync(x => x.Email == contactCreate.Email);

                if (checkEmailEntity != null)
                {
                    result.ErrorMessage = ERROR_CREATE_CONTACT_DUPLICATE_EMAIL;
                    return(result);
                }

                //Create new contactEntity by mapping contactCreate to Entities.Contact
                var contactEntity = _mapper.Map <Entities.Contact>(contactCreate);

                //Add contactEntity
                await _contactRepository.AddAsync(contactEntity);

                result.Data = _mapper.Map <Models.Contact>(contactEntity);
            }
            catch (Exception e)
            {
                result.ErrorMessage = LogError(e, "CreateContact", new object[] { contactCreate });
            }

            return(result);
        }
예제 #5
0
        public async Task AddContactAsync()
        {
            var contact = new Contact();

            await _sqlContactRepository.AddAsync(contact);

            Assert.AreEqual(1, contact.Id);
        }
예제 #6
0
 public async Task <Contact> AddContactAsync(Contact contact)
 {
     if (contact == null)
     {
         throw new System.Exception($"{nameof(DeleteContactByIdAsync)} contact can not be null");
     }
     return(await _contactRepository.AddAsync(contact));
 }
예제 #7
0
        public async Task <bool> Handle(ContactCreate request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Contact>(request.ContactCreateViewModel);

            entity = await _contactRepository.AddAsync(entity);

            return(entity.Id > 0);
        }
        public async Task Handle(ContactCreatedEvent notification, CancellationToken cancellationToken)
        {
            var contactToAdd = _mapper.Map <ContactReader>(notification.ContactWriter);

            await _contacts.AddAsync(contactToAdd, cancellationToken);

            await RaiseContactAddedEvent(contactToAdd, cancellationToken);
        }
예제 #9
0
        public async Task <Contact> AddPeopleAsync(People people)
        {
            var contact = await _contactRepository.AddAsync(people);

            await _contactRepository.UnitOfWork.SaveChangesAsync();

            return(contact);
        }
예제 #10
0
        public async Task CreateContact(GebruikerContact newContact)
        {
            await _contactRepository.AddAsync(newContact);

            if (!_contactRepository.CommitAsync().IsCompletedSuccessfully)
            {
                throw new Exception("Dit contact kon niet toegevoegd worden omdat het al bestaat!");
            }
        }
예제 #11
0
        public async Task <IActionResult> Add([FromBody] ContactCreateDto dto)
        {
            var entity = _mapper.Map <Contact>(dto);

            entity.Status  = ContactStatus.Submitted;
            entity.OwnerId = default(Guid).ToString();
            var createdContact = await _contactRepository.AddAsync(entity);

            return(CreatedAtAction(nameof(Get), new { id = createdContact.Id }, createdContact));
        }
 public async Task SaveAsync(Models.Contact contact)
 {
     if (_contactRepository.FindByIdAsync(contact.ContactId).Result == null)
     {
         _contactRepository.AddAsync(contact);
     }
     else
     {
         _contactRepository.Update(contact);
     }
 }
        public async Task <Contact> AddAsync(ContactPostDto entity)
        {
            ContactPostDtoValidator validator = new ContactPostDtoValidator();
            ValidationResult        results   = validator.Validate(entity);

            if (!results.IsValid)
            {
                throw new ValidationException("ContactPostDTO", string.Join(". ", results.Errors));
            }

            return(await userRoleRepository.AddAsync(mapper.Map <Contact>(entity)));
        }
예제 #14
0
        public async Task HandleAsync(CreateContact command)
        {
            bool isExist = await _repository.IsExist(command.Name, command.Surname, command.CompanyName);

            if (isExist)
            {
                throw new ContactAlreadyExistException(command.Name, command.Surname, command.CompanyName);
            }

            var contact = new entity.Contact(Guid.NewGuid(), command.Name, command.Surname, command.CompanyName, DateTime.Now);

            await _repository.AddAsync(contact);
        }
예제 #15
0
        /// <summary>
        /// add contact deatils
        /// </summary>
        /// <param name="newContact"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task <ContactModel> AddContact(ContactModel newContact, CancellationToken ct = default(CancellationToken))
        {
            var contact = new Contact
            {
                FirstName   = newContact.FirstName,
                LastName    = newContact.LastName,
                PhoneNumber = newContact.PhoneNumber,
                Status      = newContact.Status
            };

            contact = await _contactRepository.AddAsync(contact, ct);

            newContact.ContactId = contact.ContactId;

            return(newContact);
        }
        public async Task <IActionResult> Index([Bind("Name,Email,Mobile,Subject,Message")] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(View(contact));
            }

            contact.Date = DateTime.UtcNow;

            // Save to database
            await _repository.AddAsync(contact);

            // Send notification email
            _mailService.SendContactMailAsync(contact);

            TempData["ContactMessage"] = "Je bericht is verzonden.";
            return(RedirectToAction(nameof(Index), null, "contact"));
        }
예제 #17
0
        public async Task <ResultDto <Domain.Contact.Contact> > CreateAsync(CreateUpdateContactDto dto, CancellationToken cancellationToken)
        {
            var validationResult = _createUpdateContactDtoValidator.Validate(dto);
            var result           = new ResultDto <Domain.Contact.Contact>(validationResult);

            if (!validationResult.IsValid)
            {
                _logger.LogWarning("Contact creation validation failed: {message}", validationResult.ToString());
                return(result);
            }

            var contact = _contactFactory.Create(dto);

            await _contactRepository.AddAsync(contact);

            await _contactRepository.UnitOfWork.SaveChangesAsync(true, cancellationToken);

            result.AddData(contact);
            return(result);
        }
예제 #18
0
        public async Task <ContactResponse> SaveAsync(Contact contact)
        {
            var existingContact = await _contactRepository.GetContactAsync(contact.Name, contact.Address);

            if (existingContact != null && existingContact.Count > 0)
            {
                return(new ContactResponse(Constants.ContactConstants.Contact_AlreadyExist));
            }

            try
            {
                await _contactRepository.AddAsync(contact);

                await _unitOfWork.CompleteAsync();

                return(new ContactResponse(contact));
            }
            catch (Exception ex)
            {
                return(new ContactResponse($"An error occurred when saving the contact: {ex.Message}"));
            }
        }
예제 #19
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);
        }
예제 #20
0
        /// <summary>
        /// Adds a contact.
        /// </summary>
        /// <param name="contactResource">New contact information</param>
        /// <returns>Contact information.</returns>
        public async Task <DataResponse <ContactResource> > AddAsync(SaveContactResource contactResource)
        {
            try
            {
                if (contactResource == null)
                {
                    throw new ArgumentNullException(nameof(contactResource));
                }

                var contact = _mapper.Map <SaveContactResource, Contact>(contactResource);
                await _contactRepository.AddAsync(contact);

                await _unitOfWork.SaveChangesAsync();

                var resource = _mapper.Map <Contact, ContactResource>(contact);
                return(new DataResponse <ContactResource>(resource));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new DataResponse <ContactResource>(ex.Message));
            }
        }
예제 #21
0
        private Contact CreateContact(CreateReservationCommand request)
        {
            var contactType = _contactTypeRepository.GetByIdAsync(request.ContactTypeId).GetAwaiter().GetResult();

            if (contactType == null)
            {
                MediatorHandler.NotifyDomainNotification(
                    DomainNotification.Fail("The contact type is invalid !"));

                return(null);
            }


            var contact = new Contact(
                name: request.ContactName,
                phoneNumber: request.ContactPhone,
                birthDate: request.ContactBirthdate,
                contactType: contactType
                );

            if (!contact.IsValid())
            {
                foreach (var item in contact.ValidationResult.Errors)
                {
                    DomainNotification.Fail(item.ErrorMessage);
                }

                return(null);
            }


            _contactRepository.AddAsync(contact);

            var result = _contactRepository.CommitAsync().GetAwaiter().GetResult();

            return(result.Success ? contact : null);
        }
        public async Task <CommandResponse> Handle(CreateContactCommand request, CancellationToken cancellationToken)
        {
            var contactType = await _contactTypeRepository.GetByIdAsync(request.ContactTypeId);

            if (contactType == null)
            {
                await MediatorHandler.NotifyDomainNotification(DomainNotification.Fail("The Contact Id is not valid !"));

                return(CommandResponse.Fail());
            }

            var contact = new Contact(
                name: request.ContactName,
                phoneNumber: request.ContactPhone,
                birthDate: request.ContactBirthDate,
                contactType: contactType
                );

            if (!contact.IsValid())
            {
                foreach (var item in contact.ValidationResult.Errors)
                {
                    await MediatorHandler.NotifyDomainNotification(DomainNotification.Fail(item.ErrorMessage));
                }

                return(CommandResponse.Fail("Contact invalid !"));
            }

            await _contactRepository.AddAsync(contact);

            var result = await _contactRepository.CommitAsync();

            return(result.Success
                ? CommandResponse.Ok(contact.Id)
                : CommandResponse.Fail("Fail recording the register in database !"));
        }
예제 #23
0
 public async Task <ContactEntity> Add(ContactEntity item)
 {
     return(await _repository.AddAsync(item));
 }
        public async void Handle_ShouldCallAddAsync()
        {
            await _test.Handle(new CreateContactCommand(), default);

            A.CallTo(() => _contactRepository.AddAsync(A <Contacts> ._)).MustHaveHappenedOnceExactly();
        }
예제 #25
0
        public override async Task <int> HandleCommand(InsertCompanyCommand request, CancellationToken cancellationToken)
        {
            var id = 0;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Model.Address.CreatedDate  = DateTime.Now;
                        request.Model.Address.CreatedBy    = request.LoginSession?.Id ?? 0;
                        request.Model.Address.ModifiedDate = DateTime.Now;
                        request.Model.Address.ModifiedBy   = request.LoginSession?.Id ?? 0;
                        var addressId = await addressRepository.AddAsync(request.Model.Address);


                        request.Model.Contact.CreatedDate  = DateTime.Now;
                        request.Model.Contact.CreatedBy    = request.LoginSession?.Id ?? 0;
                        request.Model.Contact.ModifiedDate = DateTime.Now;
                        request.Model.Contact.ModifiedBy   = request.LoginSession?.Id ?? 0;
                        var contactId = await contactRepository.AddAsync(request.Model.Contact);

                        request.Model.AddressId    = addressId;
                        request.Model.ContactId    = contactId;
                        request.Model.CreatedDate  = DateTime.Now;
                        request.Model.CreatedBy    = request.LoginSession?.Id ?? 0;
                        request.Model.ModifiedDate = DateTime.Now;
                        request.Model.ModifiedBy   = request.LoginSession?.Id ?? 0;
                        id = await companyRepository.AddAsync(request.Model);

                        Company company = await companyQueries.GetByIdAsync(id);

                        var filePath = await storageFile.getCompanyFilePathAsync(company);

                        if ((request.Model.ImageData?.Length ?? 0) > Constant.MaxImageLength)
                        {
                            throw new BusinessException("Image.OutOfLength");
                        }

                        if (request.Model.IsChangedImage && (request.Model.ImageData?.Length ?? 0) > 0)
                        {
                            string type = CommonHelper.GetImageType(System.Text.Encoding.ASCII.GetBytes(request.Model.ImageData));
                            if (!CommonHelper.IsImageType(type))
                            {
                                throw new BusinessException("Image.WrongType");
                            }
                            string base64Data = request.Model.ImageData.Substring(request.Model.ImageData.IndexOf(",") + 1);
                            string fileName   = Guid.NewGuid().ToString().Replace("-", "");
                            company.LogoPath = await storageFile.SaveCompanyLogo(filePath, type, base64Data);

                            await companyRepository.UpdateAsync(company);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }
예제 #26
0
 public async Task AddNewAsync(Contact contact)
 {
     await _contactRepository.AddAsync(contact);
 }
        public async Task <IResult> AddAsync(Contact contact)
        {
            await _contactRepository.AddAsync(contact);

            return(new SuccessResult(Messages.ContactAdded));
        }
예제 #28
0
        public async Task <ActionResult <Contact> > Create([FromBody] Contact contact)
        {
            await _repository.AddAsync(contact);

            return(CreatedAtAction(nameof(Index), new { id = contact.Id }, contact));
        }