Beispiel #1
0
        public async Task <ActionResult <ContactViewModel> > GetContact(String name)
        {
            var getContactByNameQuery = new GetContactByNameQuery(name);
            var contact = await Mediator.Send(getContactByNameQuery);

            if (contact == null)
            {
                return(NotFound("Contact not found"));
            }

            return(Mapper.Map <Contact, ContactViewModel>(contact));
        }
Beispiel #2
0
        public async Task <ActionResult> AddContact([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] ContactViewModel contact)
        {
            var getContactByNameQuery = new GetContactByNameQuery(contact.Name);
            var getContact            = await Mediator.Send(getContactByNameQuery);

            if (getContact != null)
            {
                return(BadRequest("This name is already taken."));
            }

            var addContactCommand = new AddContactCommand(contact.Name, contact.Type, contact.Company, contact.PhoneNumber, contact.Email, contact.Notes);
            await Mediator.Send(addContactCommand);

            return(NoContent());
        }
        public async Task <ActionResult> AddLead([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] LeadViewModel lead)
        {
            var getLeadQuery = new GetContactByNameQuery(lead.Contact.Name);

            if (await Mediator.Send(getLeadQuery) != null)
            {
                return(BadRequest("This name is already taken."));
            }

            var  loggedUserQuery = new LoggedUserQuery();
            User user            = await Mediator.Send(loggedUserQuery);

            var addLeadCommand = new AddLeadCommand(user, lead.Contact.Name, lead.Contact.Company, lead.Contact.PhoneNumber, lead.Contact.Email, lead.Contact.Notes, lead.Contact.Source);
            await Mediator.Send(addLeadCommand);

            return(NoContent());
        }
        public async Task <ActionResult> AddOrder([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] OrderViewModel order)
        {
            var  loggedUserQuery = new LoggedUserQuery();
            User user            = await Mediator.Send(loggedUserQuery);

            var getClientQuery = new GetContactByNameQuery(order.ClientName);
            var client         = await Mediator.Send(getClientQuery);

            if (client == null)
            {
                return(NotFound("Client not found."));
            }

            var addOrderCommand = new AddOrderCommand(client, order.Type, order.Product, order.Amount, order.Price, order.Notes);
            await Mediator.Send(addOrderCommand);

            return(NoContent());
        }
        public async void Returns_Valid_Contact_By_Name()
        {
            //Arrange
            string contactName           = Context.Contacts.First().Name;
            var    queryGetContactByName = new GetContactByNameQuery(contactName);

            Mediator.Setup(x => x.Send(It.IsAny <GetContactByNameQuery>(), new CancellationToken()))
            .ReturnsAsync(new Contact());

            //Act
            var handler = new GetContactByNameQueryHandler(Context);
            var result  = await handler.Handle(queryGetContactByName, new CancellationToken());

            //Assert
            result.Should()
            .BeOfType <Contact>();
            result.Status.Should()
            .NotBeNullOrEmpty();

            DbContextFactory.Destroy(Context);
        }