コード例 #1
0
        public async Task Handle(CreateContactIntegrationEvent @event)
        {
            logger.CreateLogger(nameof(@event)).LogTrace($"New contact create request received Owner:{@event.OwnerId}-{@event.Email}.");

            CreateContactCommand createContactCommand = new CreateContactCommand
            {
                Company     = @event.Company,
                Country     = @event.Country,
                City        = @event.City,
                Phone       = @event.Phone,
                Address     = @event.Address,
                Email       = @event.Email,
                Firstname   = @event.Firstname,
                Lastname    = @event.Lastname,
                Aboutme     = @event.Aboutme,
                GroupId     = @event.GroupId,
                OwnerId     = @event.OwnerId,
                Ownername   = @event.Ownername,
                Source      = @event.Source,
                AggregateId = @event.AggregateId
            };

            await mediator.Send(createContactCommand);

            logger.CreateLogger(nameof(@event)).LogTrace($"New contact sent for processing Owner:{@event.OwnerId}-{@event.Email}.");
        }
コード例 #2
0
 public GenericCommandResult Create(
     [FromBody] CreateContactCommand command,
     [FromServices] ContactHandler handler
     )
 {
     return((GenericCommandResult)handler.Handle(command));
 }
コード例 #3
0
        public async Task Create_Invalid_Email_Should_Error()
        {
            var contact = new CreateContactCommand()
            {
                FirstName    = "Test",
                MiddleName   = "J",
                LastName     = "API",
                EmailAddress = "testc.org",
                PhoneNumber  = "432-221-1223"
            };

            HttpResponseMessage responseMessage = await httpClient.PostAsync("contacts", new StringContent(JsonSerializer.Serialize(contact), Encoding.UTF8, "application/json"));

            Assert.AreEqual(HttpStatusCode.BadRequest, responseMessage.StatusCode);
            var content = await responseMessage.Content.ReadAsStringAsync();

            var errors = JsonSerializer.Deserialize <List <ValidationError> >(content, new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            });


            Assert.AreEqual(1, errors.Count);
            Assert.AreEqual("A valid email is required", errors[0].Message);
            Assert.AreEqual("EmailAddress", errors[0].PropertyName);
        }
コード例 #4
0
 public void Create(CreateContactCommand createContactCommand)
 {
     var contact = new Contact(createContactCommand);
     contact.County = countyRepository.GetById(createContactCommand.CountyId.Value);
     contact.Country = countryRepository.GetById(createContactCommand.CountyId.Value);
     contactRepository.Save(contact);
 }
コード例 #5
0
        public void Execute_Returns_Created_Contact()
        {
            // Setup
            InitializeTestEntities();

            // Act
            Contact result = new CreateContactCommand(_serviceFactory.Object).WithCompanyId(_company.Id)
                             .SetName("Name")
                             .SetDirectPhone("111-111-1111")
                             .SetMobilePhone("222-222-2222")
                             .SetExtension("33")
                             .SetEmail("*****@*****.**")
                             .SetAssistant("Assistant")
                             .SetReferredBy("Referred By")
                             .SetNotes("Notes")
                             .RequestedByUserId(_user.Id)
                             .Execute();

            // Verify
            Assert.IsNotNull(result, "No contact was created");
            Assert.AreEqual("Name", result.Name, "The contact's name was incorrect");
            Assert.AreEqual("111-111-1111", result.DirectPhone, "The contact's direct phone was incorrect");
            Assert.AreEqual("222-222-2222", result.MobilePhone, "The contact's mobile phone was incorrect");
            Assert.AreEqual("33", result.Extension, "The contact's extension was incorrect");
            Assert.AreEqual("*****@*****.**", result.Email, "The contact's email was incorrect");
            Assert.AreEqual("Assistant", result.Assistant, "The contact's assistant was incorrect");
            Assert.AreEqual("Referred By", result.ReferredBy, "The contact's referred by was incorrect");
            Assert.AreEqual("Notes", result.Notes, "The contact's notes was incorrect");
            Assert.AreEqual(_company, result.Company, "The contact is associated with the incorrect company");
        }
コード例 #6
0
 public CreateContactService(CreateContactCommand contactCommand, IContactRepository contactRepository)
     : base(contactCommand)
 {
     _contactRepository = contactRepository;
     _contactCommand    = contactCommand;
     Run();
 }
コード例 #7
0
        public async Task <ContactDetailsDto> CreateContact(ContactCreateDto dto)
        {
            var command = new CreateContactCommand(dto);
            var result  = await _mediator.Send(command);

            return(result);
        }
コード例 #8
0
 public CreateContactHandlerTests()
 {
     _validCommand   = new CreateContactCommand("Leonardo", "Masculino", new DateTime(1984, 2, 16));;
     _invalidCommand = new CreateContactCommand("", "", new DateTime());
     _handler        = new ContactHandler(new FakeContactRepository());
     _result         = new GenericCommandResult();
 }
コード例 #9
0
 public ShowContactForm(CreateContactCommand createContactCommand)
 {
     InitializeComponent();
     this.nameLabel.Text    = createContactCommand.Name;
     this.phoneLabel.Text   = createContactCommand.Phone;
     this.addressLabel.Text = createContactCommand.Address;
 }
コード例 #10
0
ファイル: Contact.cs プロジェクト: ChrisPrentice/ArchSpike
 private void Populate(CreateContactCommand command)
 {
     FirstName = command.FirstName;
     Surname = command.Surname;
     Address1 = command.Address1;
     Address2 = command.Address2;
 }
コード例 #11
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateContactCommand();

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <ValidationException>();
        }
コード例 #12
0
        public Contact Update(int Id, CreateContactCommand command)
        {
            var contact = _contactRepository.FindOneById(Id);

            if (command.Adresse != null)
            {
                contact.Adresse = command.Adresse;
            }

            if (command.TypeContact == Core.Enum.TypeContact.Freelance)
            {
                contact.TypeContact = command.TypeContact;
                contact.NumeroTva   = command.NumeroTva;
            }
            else
            {
                contact.NumeroTva = "NoTVA";
            }
            if (command.TypeContact == Core.Enum.TypeContact.Freelance &&
                contact.TypeContact == Core.Enum.TypeContact.Freelance)
            {
                contact.NumeroTva = command.NumeroTva;
            }

            _contactRepository.Edit(contact);
            _unitOfWork.SaveChanges();

            return(contact);
        }
コード例 #13
0
        public async Task <ActionResult <ContactDTO> > CreateContact([FromBody] ContactCreateDTO contactCreateDTO)
        {
            CreateContactCommand command = mapper.Map <CreateContactCommand>(contactCreateDTO);

            ContactDTO contact = await mediator.Send(command);

            return(CreatedAtAction("GetContactById", new { id = contact.Id }, contact));
        }
        public static async Task Run(
            [QueueTrigger("contacts", Connection = "AzureWebJobsStorage")] string contactJson,
            ILogger log,
            ExecutionContext context)
        {
            var logPrefix = GetLogPrefix();

            log.LogInformation($"{logPrefix}: {contactJson}");

            var contactFromFile = JsonConvert.DeserializeObject <FileUploadContact>(contactJson);

            var config = new ConfigurationBuilder()
                         .SetBasePath(context.FunctionAppDirectory)
                         .AddJsonFile("local.settings.json", true, true)
                         .AddEnvironmentVariables()
                         .Build();
            var sqlConnectionString = config.GetConnectionString("Sql");
            var fileUploadContext   = new FileUploadContext(sqlConnectionString);

            var getEmployerQuery = new GetEmployerQuery(fileUploadContext);
            var employerInSql    = await getEmployerQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany);

            if (employerInSql == null)
            {
                // TODO Employer has to exist
            }

            var getContactQuery = new GetContactQuery(fileUploadContext);
            var contactInSql    = await getContactQuery.Execute(contactFromFile.CompanyName, contactFromFile.CreatedOnCompany);

            var contact = ContactMapper.Map(contactFromFile, contactInSql, employerInSql.Id);

            if (contactInSql == null)
            {
                log.LogInformation($"{logPrefix} Creating Contact: {contactFromFile.Contact}");

                var createEmployerCommand = new CreateContactCommand(fileUploadContext);
                await createEmployerCommand.Execute(contact);

                log.LogInformation($"{logPrefix} Created Contact: {contactFromFile.Contact}");
            }
            else
            {
                var areEqual = contactInSql.Equals(contact);
                if (!areEqual)
                {
                    log.LogInformation($"{logPrefix} Updating Contact: {contactFromFile.Contact}");

                    var updateContactCommand = new UpdateContactCommand(fileUploadContext);
                    await updateContactCommand.Execute(contact);

                    log.LogInformation($"{logPrefix} Updated Contact: {contactFromFile.Contact}");
                }
            }

            log.LogInformation($"{logPrefix} Processed Contact: {contactFromFile.Contact}");
        }
コード例 #15
0
        public async Task <IActionResult> CreateContact(CreateContactCommand createContactCommand)
        {
            createContactCommand.OwnerId = identityService.GetUserIdentity();
            var result = await mediator.Send(createContactCommand);

            return(result ?
                   (IActionResult)Ok() :
                   (IActionResult)BadRequest());
        }
コード例 #16
0
        public async Task <IActionResult> Create(CreateContactCommand command)
        {
            var response = await Mediator.Send(command);

            if (response.Errors != null && response.Errors.Any())
            {
                return(BadRequest(response.Errors));
            }
            return(Created(Request.GetDisplayUrl(), response.Data));
        }
コード例 #17
0
ファイル: BLL.cs プロジェクト: diable201/ICT
        public string CreateContact(CreateContactCommand contact)
        {
            ContactDTO contact1 = new ContactDTO();

            contact1.Id      = Guid.NewGuid().ToString();
            contact1.Name    = contact.Name;
            contact1.Address = contact.Address;
            contact1.Phone   = contact.Phone;
            return(dal.CreateContact(contact1));
        }
コード例 #18
0
        public void Execute_Initializes_Task_List()
        {
            // setup
            InitializeTestEntities();

            // Act
            Contact result = new CreateContactCommand(_serviceFactory.Object).WithCompanyId(_company.Id).RequestedByUserId(_user.Id).Execute();

            // Verify
            Assert.IsNotNull(result.Tasks, "Contact's task list was not initialized");
        }
コード例 #19
0
        public async Task <IActionResult> Create([FromBody] CreateContactCommand command)
        {
            if (command is null)
            {
                BadRequest();
            }

            command.UserId = UserId;

            return(Created("", await Mediator.Send(command)));
        }
        public async Task <OkResult> Create([FromBody] ClubContactsModel clubContactModel)
        {
            ClubContactsModel clubContactsModel = new ClubContactsModel();

            if (true /*ModelState.IsValid*/)
            {
                CreateContactCommand createContactCommand = new CreateContactCommand(clubContactModel);
                clubContactsModel = await _mediator.Send(createContactCommand);
            }
            return(clubContactsModel.Id > 0 ? Ok() : Ok());
        }
コード例 #21
0
 public JigsawContactSearchProcesses(MyJobLeadsDbContext context,
                                     IProcess <GetUserJigsawCredentialsParams, JigsawCredentialsViewModel> getJsCredProc,
                                     CreateCompanyCommand createCompanyCmd,
                                     CompanyByIdQuery compByIdQuery,
                                     CreateContactCommand createContactcmd)
 {
     _context = context;
     _getJigsawCredentialsProc = getJsCredProc;
     _createCompanyCmd         = createCompanyCmd;
     _companyByIdQuery         = compByIdQuery;
     _createContactCmd         = createContactcmd;
 }
コード例 #22
0
        public virtual ActionResult Edit(EditContactViewModel model)
        {
            Contact contact;

            try
            {
                // Determine if this is a new contact or not
                if (model.Id == 0)
                {
                    contact = new CreateContactCommand(_serviceFactory).WithCompanyId(model.Company.Id)
                              .SetAssistant(model.Assistant)
                              .SetDirectPhone(model.DirectPhone)
                              .SetEmail(model.Email)
                              .SetExtension(model.Extension)
                              .SetMobilePhone(model.MobilePhone)
                              .SetName(model.Name)
                              .SetNotes(model.Notes)
                              .SetTitle(model.Title)
                              .SetReferredBy(model.ReferredBy)
                              .RequestedByUserId(CurrentUserId)
                              .Execute();
                }
                else
                {
                    contact = new EditContactCommand(_serviceFactory).WithContactId(model.Id)
                              .SetAssistant(model.Assistant)
                              .SetDirectPhone(model.DirectPhone)
                              .SetEmail(model.Email)
                              .SetExtension(model.Extension)
                              .SetMobilePhone(model.MobilePhone)
                              .SetName(model.Name)
                              .SetNotes(model.Notes)
                              .SetTitle(model.Title)
                              .SetReferredBy(model.ReferredBy)
                              .RequestedByUserId(CurrentUserId)
                              .Execute();
                }

                return(RedirectToAction(MVC.Contact.Details(contact.Id)));
            }

            catch (ValidationException ex)
            {
                foreach (var error in ex.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }

                // Retrieve the company from the database for the sidebar
                model.Company = new CompanySummaryViewModel(new CompanyByIdQuery(_unitOfWork, _companyAuthProcess).WithCompanyId(model.Company.Id).Execute());
                return(View(model));
            }
        }
コード例 #23
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (createContactForm.ShowDialog() == DialogResult.OK)
     {
         CreateContactCommand command = new CreateContactCommand();
         command.Name  = createContactForm.nameTxtBx.Text;
         command.Phone = createContactForm.phoneTxtBx.Text;
         command.Addr  = createContactForm.addressTxtBx.Text;
         bll.CreateContact(command);
         bindingSource1.DataSource = bll.GetContacts();
     }
 }
コード例 #24
0
        public ActionResult Create(ContactCreateModel model)
        {
            var command = new CreateContactCommand()
            {
                ContactId = Guid.NewGuid(),
                Name      = model.Name
            };

            createContactHandler.Handle(command);

            return(RedirectToAction("Index"));
        }
コード例 #25
0
 public void CreateContactCommandTest()
 {
     var createContactCommand = new CreateContactCommand
     {
         PersonId       = "b9a3d7bf-c53b-4cca-8030-38d8f15ea6ca",
         ContactInfoArg = new ContactInfoArg
         {
             ContactUrl        = "*****@*****.**",
             ContactMechTypeId = "FACEBOOK"
         }
     };
     var result = _service.InvokeCommand(createContactCommand);
 }
コード例 #26
0
        private void DataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int row  = Convert.ToInt32(bindingNavigatorPositionItem.Text) - 1;
            var text = dataGridView1.Rows[row];
            CreateContactCommand contact = new CreateContactCommand();

            contact.Name    = text.Cells[1].Value.ToString();
            contact.Phone   = text.Cells[2].Value.ToString();
            contact.Address = text.Cells[3].Value.ToString();
            ContactDetails contactDetails = new ContactDetails(contact);

            contactDetails.ShowDialog();
        }
コード例 #27
0
        public void Execute_Indexes_Created_Contact()
        {
            // Setup
            InitializeTestEntities();

            // Act
            Contact contact = new CreateContactCommand(_serviceFactory.Object)
                              .WithCompanyId(_company.Id)
                              .RequestedByUserId(_user.Id)
                              .Execute();

            // Verify
            _searchProvider.Verify(x => x.Index(contact), Times.Once());
        }
コード例 #28
0
        private void AddContact(object sender, EventArgs e)
        {
            CreateContactForm createContactForm = new CreateContactForm();

            if (createContactForm.ShowDialog() == DialogResult.OK)
            {
                CreateContactCommand command = new CreateContactCommand();
                command.Name    = createContactForm.nameTxtBx.Text;
                command.Phone   = createContactForm.phoneTxtBx.Text;
                command.Address = createContactForm.addressTxtBx.Text;
                bll.CreateContact(command);
                UpdateView();
            }
        }
コード例 #29
0
        public async Task Create_Valid_Input_Should_Create_Contact()
        {
            var contact = new CreateContactCommand()
            {
                FirstName    = "Test",
                MiddleName   = "J",
                LastName     = "API",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "432-221-1223"
            };

            HttpResponseMessage responseMessage = await httpClient.PostAsync("contacts", new StringContent(JsonSerializer.Serialize(contact), Encoding.UTF8, "application/json"));

            Assert.AreEqual(HttpStatusCode.Created, responseMessage.StatusCode);
        }
コード例 #30
0
        public void Throws_ValidationException_DateOfBirth_Default()
        {
            // Arrange
            var sut = new CreateContactValidator();
            var cmd = new CreateContactCommand {
                Name = "A", Address = "A"
            };

            // Act
            var result = sut.Validate(cmd);

            // Assert
            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, e => e.PropertyName == nameof(cmd.DateOfBirth));
        }
コード例 #31
0
        public async Task <IActionResult> Create([FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var command = new CreateContactCommand {
                Contact = contact
            };

            await _createContactCommandHandler.HandleAsync(command);

            return(CreatedAtAction("GetContact", new { id = command.Contact.ContactId }, command.Contact));
        }
コード例 #32
0
        public void Throws_ValidationException_Address_Empty()
        {
            // Arrange
            var sut = new CreateContactValidator();
            var cmd = new CreateContactCommand {
                Name = "A", Address = string.Empty, DateOfBirth = DateTime.Now
            };

            // Act
            var result = sut.Validate(cmd);

            // Assert
            Assert.False(result.IsValid);
            Assert.Contains(result.Errors, e => e.PropertyName == nameof(cmd.Address));
        }
コード例 #33
0
        public void Validate(CreateContactCommand contact)
        {
            const int minimumDescriptionLength = 10;

            if (Guid.Empty.Equals(contact.ContactId))
                throw new ValidationException("ContactId has not been set by the client");

            if (string.IsNullOrWhiteSpace(contact.Name))
                throw new ValidationException("name is required");

            if (contact.Name.Length < minimumDescriptionLength)
            {
                throw new ValidationException(string.Format("Description must be at least {0} characters long", minimumDescriptionLength));
            }
        }
コード例 #34
0
ファイル: Contact.cs プロジェクト: ChrisPrentice/ArchSpike
 public Contact(CreateContactCommand command)
 {
     Populate(command);
 }