Exemple #1
0
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse response = new CreateCustomerResponse();

            var email = new EmailAddress(request.Email);
            var name  = new Name(request.FirstName, request.SecondName);

            var customer = new Customer(request.CustomerIdentityToken, email, name);

            ThrowExceptionIfCustomerIsInvalid(customer);

            _customerRepository.Add(customer);
            _uow.Commit();

            response.Customer = customer.ConvertToCustomerDetailView();

            return(response);
        }
Exemple #2
0
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse response = new CreateCustomerResponse();
            Customer customer = new Customer();

            customer.UserId     = request.UserId;
            customer.Email      = request.Email;
            customer.FirstName  = request.FirstName;
            customer.SecondName = request.SecondName;

            customer.ThrowExceptionIfInvalid();
            _customerRepository.Add(customer);
            _uow.Commit();

            response.Customer = _mapper.Map <Customer, CustomerView>(customer);

            return(response);
        }
Exemple #3
0
        public JsonResult Create(CustomerDetailView vm)
        {
            CreateCustomerRequest request = new CreateCustomerRequest();

            request.CompanyName  = vm.CompanyName;
            request.ContactName  = vm.ContactName;
            request.ContactTitle = vm.ContactTitle;
            request.Address      = vm.Address;
            request.City         = vm.City;
            request.Region       = vm.Region;
            request.PostalCode   = vm.PostalCode;
            request.Country      = vm.Country;
            request.Phone        = vm.Phone;
            request.Fax          = vm.Fax;
            CreateCustomerResponse response = _customerService.CreateCustomer(request);

            return(Json(response));
        }
        public override async Task CreateCustomer(
            CreateCustomerResponse request,
            IServerStreamWriter <CustomerModel> responseStream,
            ServerCallContext context)
        {
            List <CustomerModel> customers = new List <CustomerModel>();

            customers.Add(DefaultCustomerModelResponse);
            customers.Add(DefaultCustomerModelResponse);
            customers.Add(DefaultCustomerModelResponse);

            foreach (var customer in customers)
            {
                await Task.Delay(3000);

                await responseStream.WriteAsync(customer);
            }
        }
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse response = new CreateCustomerResponse();
            Customer customer = new Customer();

            customer.IdentityToken = request.CustomerIdentityToken;
            customer.Email         = request.Email;
            customer.FirstName     = request.FirstName;
            customer.SecondName    = request.SecondName;

            ThrowExceptionIfCustomerIsInvalid(customer);

            _customerRepository.Add(customer);
            _uow.Commit();

            response.Customer = customer.ConvertToCustomerDetailView();

            return(response);
        }
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            CreateCustomerResponse response = new CreateCustomerResponse();
            Customer customer = new Customer();

            customer.CompanyName          = request.CompanyName;
            customer.ContactName          = request.ContactName;
            customer.ContactTitle         = request.ContactTitle;
            customer.Address              = request.Address;
            customer.City                 = request.City;
            customer.Region               = request.Region;
            customer.PostalCode           = request.PostalCode;
            customer.Country              = request.Country;
            customer.Phone                = request.Phone;
            customer.Fax                  = request.Fax;
            customer.CustomerDemographics = request.CustomerDemographics.ConvertToCustomerDemographics();
            customer.Orders               = request.Orders.ConvertToOrders();

            if (customer.GetBrokenRules().Count() > 0)
            {
                response.Errors = customer.GetBrokenRules().ToList();
            }
            else
            {
                try {
                    _customerRepository.Add(customer);
                    _uow.Commit();
                    response.Errors = new List <BusinessRule>();
                } catch (Exception ex)
                {
                    List <BusinessRule> errors = new List <BusinessRule>();
                    do
                    {
                        errors.Add(new BusinessRule("DAL", "DAL_ERROR: " + ex.Message));
                        ex = ex.InnerException;
                    } while (ex != null);

                    response.Errors = errors;
                }
            }

            return(response);
        }
        public int AddCustomer(CreateCustomerRequest ObjCreateCustomerRequest)
        {
            try
            {
                DateTime date = DateTime.Now;

                string        connectionstring = "data source=.;" + "database=Binoy;" + "Integrated Security=true";
                SqlConnection connection       = new SqlConnection(connectionstring);
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_addCustomer_s2por";
                cmd.Connection  = connection;
                cmd.Parameters.AddWithValue("@Customer_SSN_ID", ObjCreateCustomerRequest.Customer_ssn_Id);
                cmd.Parameters.AddWithValue("@Customer_Name", ObjCreateCustomerRequest.Customer_Name);
                cmd.Parameters.AddWithValue("@Customer_Age", ObjCreateCustomerRequest.Customer_Age);
                cmd.Parameters.AddWithValue("@Customer_Address", ObjCreateCustomerRequest.Customer_Address);
                cmd.Parameters.AddWithValue("@Customer_State", ObjCreateCustomerRequest.Customer_State);
                cmd.Parameters.AddWithValue("@Customer_City", ObjCreateCustomerRequest.Customer_City);
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@Customer_ID", 0);
                cmd.Parameters["@Customer_ID"].Direction = ParameterDirection.Output;

                int Rowaffected = cmd.ExecuteNonQuery();
                connection.Close();
                CreateCustomerResponse ObjCreateCustomerResponse = new CreateCustomerResponse();
                if (Rowaffected > 0)
                {
                    ObjCreateCustomerResponse.CustomerID = Convert.ToInt32(cmd.Parameters["@Customer_ID"].Value);
                    return(ObjCreateCustomerResponse.CustomerID);
                }
                else
                {
                    return(0);
                }
            }
            catch (SqlException e)
            {
                return(1);
            }
        }
Exemple #8
0
        public static async Task <HttpResponseMessage> CreateCustomer([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            // Get request body
            var body = await req.Content.ReadAsStringAsync();

            var request = JsonConvert.DeserializeObject <CreateCustomerRequest>(body, new JsonConverter[] { new GuidJsonConverter() });

            if (request == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "No Valid Data submitted."));
            }

            Customer customer = request.Customer;

            // Create the response
            var response = new CreateCustomerResponse();

            // If we're not provided a valid First Name throw an error
            if (string.IsNullOrEmpty(customer.FirstName))
            {
                response.Message = "No FirstName was provided";
                return(req.CreateResponse(HttpStatusCode.ExpectationFailed, response));
            }

            // Check for existing customers
            Customer exitingCustomer = await FaceClient.Instance.IdentifyCustomerFace(customer.FaceId);

            if (exitingCustomer != null)
            {
                response.Message  = "Customer already exists";
                response.Customer = exitingCustomer;
                return(req.CreateResponse(HttpStatusCode.Conflict, response));
            }

            // If not register a new Person and store in the database
            customer = await FaceClient.Instance.RegisterNewCustomer(customer, request.ImageUrl);

            response.Customer = customer;

            return(req.CreateResponse(HttpStatusCode.OK, response));
        }
        public CreateCustomerResponse CreateCustomer(string email)
        {
            HttpContent content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("email", email)
            });

            content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            HttpResponseMessage response = (_client.PostAsync("https://api.stripe.com/v1/customers", content))
                                           .GetAwaiter().GetResult();

            var createCustomerResponse = new CreateCustomerResponse();

            if (response.IsSuccessStatusCode)
            {
                createCustomerResponse =
                    JsonConvert.DeserializeObject <CreateCustomerResponse>(response.Content.ReadAsStringAsync().Result);
            }

            return(createCustomerResponse);
        }
Exemple #10
0
        public void Should_Return_Response(IMapper mapper,
                                           Mock <ICustomerBuilder> builder,
                                           Mock <ICustomerRepository> repo,
                                           Mock <ConsumeContext <ICreateCustomerRequest> > context,
                                           Mock <ICreateCustomerRequest> request, RegisteredUserDTO dto)
        {
            //could create a customization for this (see Framework/Customizations folder in this project for example)
            Domain.Customer customer = Domain.Customer.Create(dto.FirstName, dto.LastName, dto.Email, dto.AnonymousId);


            //just stuff to make the test move forward
            request.Setup(x => x.RegisteredUser).Returns(dto);
            builder.Setup(x => x.Build(dto)).Returns(customer);

            repo.Setup(x => x.SaveAsync(customer)).ReturnsAsync(customer);

            context.Setup(x => x.Message).Returns(request.Object);


            //call back for the context.RespondAsync -- point of this test is to make sure
            //that a response is created, normally this would go to the message queue.
            //The Consume method doesn't give a direct response. This could also be handled
            //by creating an in-memory queue for masstransit
            CreateCustomerResponse          returnedResponse = null;
            Action <CreateCustomerResponse> testCallBack     = (x) =>
            {
                returnedResponse = x;
            };


            context.Setup(x => x.RespondAsync(It.IsAny <CreateCustomerResponse>()))
            .Callback(testCallBack);

            var sut = new CreateCustomerConsumer(builder.Object, repo.Object, mapper);

            sut.Consume(context.Object).ConfigureAwait(false);


            Assert.NotNull(returnedResponse);
        }
Exemple #11
0
        public async Task TestSuccess()
        {
            // Arrange
            Mock <IDataRepository <Customer, Guid> > mockRepository = new Mock <IDataRepository <Customer, Guid> >();

            mockRepository.Setup(m => m.Add(It.IsAny <Customer>()));
            string name = "Unit Test";
            CreateCustomerRequest request = new CreateCustomerRequest()
            {
                Name = name
            };
            CreateCustomerCommand sut = new CreateCustomerCommand(MockHelpers.GetLogger <CreateCustomerCommand>(), mockRepository.Object);

            // Act
            CreateCustomerResponse result = await sut.Handle(request, default);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Customer);
            Assert.AreEqual(name, result.Customer.Name);
            mockRepository.VerifyAll();
            mockRepository.Verify(m => m.Add(It.IsAny <Customer>()), Times.Once);
        }
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest request)
        {
            var response = new CreateCustomerResponse
            {
                IsSuccessful = false,
                Message      = ""
            };

            try
            {
                var createdCustomer = _context.Add(request.Customer);
                _context.SaveChanges();

                response.IsSuccessful    = true;
                response.CreatedCustomer = createdCustomer.Entity;
            }
            catch (Exception ex)
            {
                response.Message = ex.ToString();
            }

            return(response);
        }