示例#1
0
        public List <CustomerModel> GetOrderCustomers([FromBody] GetOrderCustomersRequestModel requestModel)
        {
            var customers = new List <CustomerModel>();

            var userCustomers = Context.Customers.Where(o => o.CreateUser == requestModel.Username).Select(o => new CustomerModel
            {
                CustomerId       = o.CustomerId,
                CustomerName     = o.CustomerName,
                CompanyProfileId = o.CompanyProfileId,
                CustomerDetails  = o.CustomerDetails,
                AccountNo        = o.AccountNo,
                ContactNo        = o.ContactNo,
                EmailAddress     = o.EmailAddress,
                MobileNo         = o.MobileNo,
                CreateDate       = o.CreateDate,
                CreateUser       = o.CreateUser
            }).ToList();

            if (userCustomers != null)
            {
                customers.AddRange(userCustomers);
            }

            if (requestModel.CompanyProfileId != 0)
            {
                var companyCustomers = Context.Customers.Where(o => o.CreateUser != requestModel.Username && o.CompanyProfileId == requestModel.CompanyProfileId).Select(o => new CustomerModel
                {
                    CustomerId       = o.CustomerId,
                    CustomerName     = o.CustomerName,
                    CompanyProfileId = o.CompanyProfileId,
                    CustomerDetails  = o.CustomerDetails,
                    AccountNo        = o.AccountNo,
                    ContactNo        = o.ContactNo,
                    EmailAddress     = o.EmailAddress,
                    MobileNo         = o.MobileNo,
                    CreateDate       = o.CreateDate,
                    CreateUser       = o.CreateUser
                }).ToList();

                if (companyCustomers != null)
                {
                    customers.AddRange(companyCustomers);
                }
            }

            return(customers);
        }
示例#2
0
        public void GetUser_Company_Customers_ReturnsCustomerModel()
        {
            // given
            var resources    = new Resources();
            var requestModel = new GetOrderCustomersRequestModel {
                CompanyProfileId = resources.CompanyProfileId, Username = resources.TestUsername
            };
            var responseModel = new List <CustomerModel>
            {
                new CustomerModel
                {
                    CompanyProfileId = resources.CompanyProfileId,
                    CustomerId       = 1,
                    CustomerName     = "City of Cape Town",
                    CreateUser       = resources.TestUsername,
                    CreateDate       = DateTime.Now
                },
                new CustomerModel
                {
                    CompanyProfileId = resources.CompanyProfileId,
                    CustomerId       = 2,
                    CustomerName     = "The Juggernauts",
                    CreateUser       = resources.TestUsername,
                    CreateDate       = DateTime.Now
                },
                new CustomerModel
                {
                    CompanyProfileId = resources.CompanyProfileId,
                    CustomerId       = 2,
                    CustomerName     = "Water Inc.",
                    CreateUser       = resources.TestUsername,
                    CreateDate       = DateTime.Now
                }
            };

            resources.MockApiCaller.AddMockResponse("WebApi:Orders:GetOrderCustomers", requestModel, responseModel);

            // when
            var result = resources.Controller.GetOrderCustomers() as JsonResult;

            // then
            Assert.IsNotNull(result);
            var model = (List <CustomerModel>)result.Value;

            Assert.IsNotNull(model);
            Assert.AreEqual(3, model.Count);

            Assert.AreEqual(responseModel[0].CompanyProfileId, model[0].CompanyProfileId);
            Assert.AreEqual(responseModel[0].CustomerName, model[0].CustomerName);
            Assert.AreEqual(responseModel[0].CustomerId, model[0].CustomerId);
            Assert.AreEqual(responseModel[0].CreateDate, model[0].CreateDate);
            Assert.AreEqual(responseModel[0].CreateUser, model[0].CreateUser);

            Assert.AreEqual(responseModel[1].CompanyProfileId, model[1].CompanyProfileId);
            Assert.AreEqual(responseModel[1].CustomerName, model[1].CustomerName);
            Assert.AreEqual(responseModel[1].CustomerId, model[1].CustomerId);
            Assert.AreEqual(responseModel[1].CreateDate, model[1].CreateDate);
            Assert.AreEqual(responseModel[1].CreateUser, model[1].CreateUser);

            Assert.AreEqual(responseModel[2].CompanyProfileId, model[2].CompanyProfileId);
            Assert.AreEqual(responseModel[2].CustomerName, model[2].CustomerName);
            Assert.AreEqual(responseModel[2].CustomerId, model[2].CustomerId);
            Assert.AreEqual(responseModel[2].CreateDate, model[2].CreateDate);
            Assert.AreEqual(responseModel[2].CreateUser, model[2].CreateUser);
        }