Ejemplo n.º 1
0
        public ActionResult IndexCustomer(CustomerCriteria criteria, string currentFilter, int?page = 1)
        {
            int pageNumber = (page ?? 1);

            this.ViewBag.CurrentFilter = criteria;
            if (!string.IsNullOrEmpty(currentFilter))
            {
                return(this.IndexCustomer(criteria, page));
            }
            var obj  = CustomerList.GetCustomerList().OrderByDescending(x => x.CreatedDate).ToPagedList(pageNumber, this.pageSize);
            var list = new ISAT.Web.ViewModel.CustomerViewModel();

            foreach (var item in obj)
            {
                var cust = Business.Customer.NewCustomer();
                cust.FirstName   = item.FirstName;
                cust.LastName    = item.LastName;
                cust.Email       = item.Email;
                cust.CustNo      = item.CustNo;
                cust.CompanyName = item.CompanyName;
                cust.CreatedDate = item.CreatedDate;
                cust.CreatedBy   = item.CreatedBy;
                list.ListCustomer.Add(cust);
            }

            var viewModel = new CustomerViewModel()
            {
                ListCustomer = list.ListCustomer.ToList(),
                Criteria     = new CustomerCriteria()
            };
            var onePageOfProducts = list;

            ViewBag.OnePageOfProducts = obj;
            return(View(viewModel));
        }
        public void FindByCriteria_GivenCriteria_ItReturnsTheRightCustomer()
        {
            // arrange
            MainContext.Customers.Add(new Customer
            {
                Firstname = "Lionel",
                Lastname  = "Repellin",
            });

            MainContext.SaveChanges();

            var criteria = new CustomerCriteria
            {
                Firstname = "Lionel",
                Lastname  = "Repellin"
            };

            // act
            var customers = _customerRepository.FindByCriteria(criteria);
            var customer  = customers.First();

            // assert
            Assert.That(customer, Has.Property("Firstname").EqualTo(criteria.Firstname));
            Assert.That(customer, Has.Property("Lastname").EqualTo(criteria.Lastname));
        }
Ejemplo n.º 3
0
        async Task <FilterResponse> ICustomerAccess.FilterAsync(CustomerCriteria criteria)
        {
            Entity.ICustomerRepository    customerRepository = RepositoryFactory.Create <Entity.ICustomerRepository>();
            IEnumerable <Entity.Customer> entityCustomer     = customerRepository.Get <Entity.Customer>(criteria.NameCriteria);

            return(MapEntityToDTO(entityCustomer));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set (add, update, delete) customer value.
        /// </summary>
        /// <param name="request">Customer request message.</param>
        /// <returns>Customer response message.</returns>
        public CustomerResponse SetCustomers(CustomerRequest request)
        {
            CustomerResponse response = new CustomerResponse();

            response.CorrelationId = request.RequestId;

            // Validate client tag, access token, and user credentials
            if (!ValidRequest(request, response, Validate.All))
            {
                return(response);
            }

            // Transform customer data transfer object to customer business object
            Customer customer = Mapper.FromDataTransferObject(request.Customer);

            // Validate customer business rules

            if (request.Action != "Delete")
            {
                if (!customer.Validate())
                {
                    response.Acknowledge = AcknowledgeType.Failure;

                    foreach (string error in customer.ValidationErrors)
                    {
                        response.Message += error + Environment.NewLine;
                    }

                    return(response);
                }
            }

            // Run within the context of a database transaction. Currently commented out.
            // The Decorator Design Pattern.
            //using (TransactionDecorator transaction = new TransactionDecorator())
            {
                if (request.Action == "Create")
                {
                    customerDao.InsertCustomer(customer);
                    response.Customer     = Mapper.ToDataTransferObject(customer);
                    response.RowsAffected = 1;
                }
                else if (request.Action == "Update")
                {
                    response.RowsAffected = customerDao.UpdateCustomer(customer);
                    response.Customer     = Mapper.ToDataTransferObject(customer);
                }
                else if (request.Action == "Delete")
                {
                    CustomerCriteria criteria = request.Criteria as CustomerCriteria;
                    Customer         cust     = customerDao.GetCustomer(criteria.CustomerId);

                    response.RowsAffected = customerDao.DeleteCustomer(cust);
                }

                //transaction.Complete();
            }

            return(response);
        }
        public IEnumerable <CustomerData> FindByFirstnameAndLastname(string firstname, string lastname)
        {
            var criteria = new CustomerCriteria
            {
                Firstname = firstname,
                Lastname  = lastname
            };
            var customers = _customerRepository.FindByCriteria(criteria);

            return(_dataConverter.Convert <IEnumerable <Customer>, IEnumerable <CustomerData> >(customers));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Request customer data.
        /// </summary>
        /// <param name="request">Customer request message.</param>
        /// <returns>Customer response message.</returns>
        public CustomerResponse GetCustomers(CustomerRequest request)
        {
            CustomerResponse response = new CustomerResponse();

            response.CorrelationId = request.RequestId;

            // Validate client tag, access token, and user credentials
            if (!ValidRequest(request, response, Validate.All))
            {
                return(response);
            }

            CustomerCriteria criteria = request.Criteria as CustomerCriteria;
            string           sort     = criteria.SortExpression;

            if (request.LoadOptions.Contains("Customers"))
            {
                IEnumerable <Customer> customers;
                if (!criteria.IncludeOrderStatistics)
                {
                    // Simple customer list without order information
                    customers = customerDao.GetCustomers(criteria.SortExpression);
                }
                else if (sort.IndexOf("NumOrders") >= 0 || sort.IndexOf("LastOrderDate") >= 0)
                {
                    // Sort order is handled by the Order Dao
                    IList <Customer> list = customerDao.GetCustomers();
                    customers = orderDao.GetOrderStatistics(list, sort);
                }
                else
                {
                    // Sort order is handled by the Customer Dao, but alse need order statistics
                    IList <Customer> list = customerDao.GetCustomers(sort);
                    customers = orderDao.GetOrderStatistics(list);
                }
                response.Customers = customers.Select(c => Mapper.ToDataTransferObject(c)).ToList();
            }

            if (request.LoadOptions.Contains("Customer"))
            {
                Customer customer = customerDao.GetCustomer(criteria.CustomerId);
                if (request.LoadOptions.Contains("Orders"))
                {
                    customer.Orders = orderDao.GetOrders(customer.CustomerId);
                }

                response.Customer = Mapper.ToDataTransferObject(customer);
            }

            return(response);
        }
Ejemplo n.º 7
0
        public async Task Can_Insert_Customer()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(
                name: "Innovation",
                userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var insertCustomerCommandResult = await dispatcher.Command(command : insertCustomerCommand, suppressExceptions : false);

            // Assert
            Assert.True(condition: insertCustomerCommandResult.Success);
        }
Ejemplo n.º 8
0
        public void Can_Handle_Insert_Customer()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(
                name: "Innovation",
                userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var canCommand = dispatcher.CanCommand(command: insertCustomerCommand);

            // Assert
            Assert.True(condition: canCommand);
        }
Ejemplo n.º 9
0
        public async Task Can_Handle_Validation_Attributes()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(
                name: "I",
                userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var commandResult = (await dispatcher.Command(command: insertCustomerCommand)).As<CommandResult>();

            // Assert
            Assert.False(condition: commandResult.Success);
            Assert.Equal(expected: "Name needs to be between 3 and 30 characters", actual: commandResult.Errors[0]);
        }
Ejemplo n.º 10
0
        public async Task Can_Handle_Required_Validation_Attributes()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(name: null, userName: null);
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var commandResult = (await dispatcher.Command(command: insertCustomerCommand)).As<CommandResult>();

            // Assert
            Assert.False(condition: commandResult.Success);
            Assert.Equal(expected: 2, actual: commandResult.Errors.Length);
            Assert.Equal(expected: "The Name field is required.", actual: commandResult.Errors[0]);
            Assert.Equal(expected: "The UserName field is required.", actual: commandResult.Errors[1]);
        }
Ejemplo n.º 11
0
        public async Task Can_Handle_Min_Length_Validation_Attributes()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(name: "aa", userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var commandResult = (await dispatcher.Command(command: insertCustomerCommand)).As<CommandResult>();

            // Assert
            Assert.False(condition: commandResult.Success);
            Assert.Equal(expected: 2, actual: commandResult.Errors.Length);
            Assert.Equal(expected: "Name needs to be between 3 and 30 characters", actual: commandResult.Errors[0]);
            Assert.Equal(expected: "UserName needs to be between 10 and 35 characters", actual: commandResult.Errors[1]);
        }
Ejemplo n.º 12
0
        public async Task Can_Run_Intercept_Expecting_True()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(
                name: "Innovation",
                userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var insertCustomerCommandResult = await dispatcher.Command(command : insertCustomerCommand, suppressExceptions : false);

            // Assert
            Assert.NotNull(@object: insertCustomerCommand.Criteria.ExistsOnGithub);
            Assert.True(condition: insertCustomerCommand.Criteria.ExistsOnGithub.Value);
        }
Ejemplo n.º 13
0
        public async Task Can_Handle_Regex_Validation_Attributes()
        {
            // Arrange
            var insertCustomerCriteria = new CustomerCriteria(
                name: "0123#",
                userName: "******");
            var insertCustomerCommand = new InsertCustomer(customerCriteria: insertCustomerCriteria);

            // Act
            var dispatcher = this.GetDispatcher();
            var commandResult = (await dispatcher.Command(command: insertCustomerCommand)).As<CommandResult>();

            // Assert
            Assert.False(condition: commandResult.Success);
            Assert.Equal(expected: 2, actual: commandResult.Errors.Length);
            Assert.Equal(expected: "Name only allows alphanumeric characters", actual: commandResult.Errors[0]);
            Assert.Equal(expected: "UserName only allows alphanumeric characters", actual: commandResult.Errors[1]);
        }
        public async Task Can_Fail_Handle_Context_Not_Set_In_Command_Handler()
        {
            // Arrange
            var customerCriteria = new CustomerCriteria(
                name: "Innovation",
                userName: "******");
            Guid customerId            = Guid.NewGuid();
            var  updateCustomerCommand = new UpdateCustomer(customerCriteria: customerCriteria, customerId: customerId);

            // Act
            var dispatcher = this.GetDispatcher();
            var updateCustomerCommandResult = (await dispatcher.Command(command: updateCustomerCommand)).As <CommandResult>();

            // Assert
            Assert.False(condition: updateCustomerCommandResult.Success);
            Assert.Single(updateCustomerCommandResult.Errors);
            Assert.Equal(expected: "Dispatcher Context Not Set", actual: updateCustomerCommandResult.Errors[0]);
        }
        public async Task Can_Get_Context_In_Command_Handler()
        {
            // Arrange
            var customerCriteria = new CustomerCriteria(
                name: "Innovation",
                userName: "******");
            Guid customerId              = Guid.NewGuid();
            var  updateCustomerCommand   = new UpdateCustomer(customerCriteria: customerCriteria, customerId: customerId);
            var  sharedDispatcherContext = new SharedDispatcherContext();

            // Act
            var dispatcher = this.GetDispatcher();

            dispatcher.SetContext(dispatcherContext: sharedDispatcherContext);
            var updateCustomerCommandResult = (await dispatcher.Command(command: updateCustomerCommand)).As <CommandResult>();

            // Assert
            Assert.True(condition: updateCustomerCommandResult.Success);
        }
Ejemplo n.º 16
0
        public ActionResult ExportExcelCustomerData(CustomerCriteria criteria)
        {
            var headerDictionary = new Dictionary <string, string>();

            this.ViewBag.CurrentFilter = criteria;

            var obj  = CustomerList.GetCustomerList();
            var list = new ISAT.Web.ViewModel.CustomerViewModel();

            foreach (var item in obj)
            {
                var cust = Business.Customer.NewCustomer();
                cust.FirstName   = item.FirstName;
                cust.LastName    = item.LastName;
                cust.Email       = item.Email;
                cust.CustNo      = item.CustNo;
                cust.CompanyName = item.CompanyName;
                cust.CreatedDate = item.CreatedDate;
                cust.CreatedBy   = item.CreatedBy;
                list.ListCustomer.Add(cust);
            }

            var viewModel = new CustomerViewModel()
            {
                ListCustomer = list.ListCustomer.OrderByDescending(x => x.CreatedDate).ToList(),
                Criteria     = new CustomerCriteria()
            };

            try
            {
                IExporter exporter = new CustomerDataExcelExporter(this.Response, viewModel.ListCustomer);
                exporter.Export();
            }
            catch
            {
                throw;
            }
            return(this.View("IndexCustomer", viewModel));
        }
Ejemplo n.º 17
0
        public ActionResult IndexCustomer(CustomerCriteria criteria, int?page = 1)
        {
            int pageNumber = (page ?? 1);

            this.ViewBag.CurrentFilter = criteria;

            var obj = CustomerList.GetCustomerList().Where(o => (criteria.FirstName == null || o.FirstName.ToLower().Contains(criteria.FirstName.ToLower())) &&
                                                           (criteria.LastName == null || o.LastName.ToLower().Contains(criteria.LastName.ToLower())) &&
                                                           (criteria.Email == null || o.Email.ToLower().Contains(criteria.Email.ToLower())) &&
                                                           (criteria.CompanyName == null || o.CompanyName.ToLower().Contains(criteria.CompanyName.ToLower()) &&
                                                            (criteria.CustNo == null || o.CustNo.ToLower().Contains(criteria.CustNo.ToLower()))))
                      .Select(o => o).ToPagedList(pageNumber, this.pageSize);
            var list = new ISAT.Web.ViewModel.CustomerViewModel();

            foreach (var item in obj)
            {
                var cust = Business.Customer.NewCustomer();
                cust.FirstName   = item.FirstName;
                cust.LastName    = item.LastName;
                cust.Email       = item.Email;
                cust.CustNo      = item.CustNo;
                cust.CompanyName = item.CompanyName;
                cust.CreatedDate = item.CreatedDate;
                cust.CreatedBy   = item.CreatedBy;
                list.ListCustomer.Add(cust);
            }
            var viewModel = new CustomerViewModel()
            {
                ListCustomer = list.ListCustomer.OrderByDescending(x => x.CreatedDate).ToList(),
                Criteria     = new CustomerCriteria()
            };
            var onePageOfProducts = list;

            ViewBag.OnePageOfProducts = obj;
            return(View(viewModel));
        }
Ejemplo n.º 18
0
        public virtual void SaveOrUpdateCustomer(Customer customer, string Code)
        {
            try
            {
                //if (corporation.IsNullOrWhiteSpace()) throw new ArgumentNullException("corporation");
                //SetInvOrgIdByCorporation(corporation);
                using (var trans = RF.TransactionScope(BDEntityDataProvider.ConnectionStringName))
                {
                    //获取客户
                    var criteria = new CustomerCriteria()
                    {
                        PagingInfo = new PagingInfo(1, int.MaxValue)
                    };
                    criteria.Code = customer.Code;
                    var existCustomer = DomainControllerFactory.Create <CustomerController>()
                                        .GetList(criteria).Concrete().FirstOrDefault() ?? customer;

                    //ItemExtendsion.SetErpUpdate(item, item.UpdateDate);
                    existCustomer.Name      = customer.Name;
                    existCustomer.SalesArea = customer.SalesArea;

                    //customer.PersistenceStatus = existCustomer.PersistenceStatus;
                    //customer.Id = existCustomer.Id;
                    //organization.DataSource = EumDataSource.ERP;

                    InvOrgIdExtension.SetInvOrgId(customer, PlatformEnvironment.InvOrgId);
                    RF.Save(existCustomer);

                    trans.Complete();
                }
            }
            catch (Exception e)
            {
                throw new Exception("客户基础主数据下载异常:" + e.Message);
            }
        }
Ejemplo n.º 19
0
        public HttpResponseMessage Search(CustomerSearchModel model)
        {
            if (ModelState.IsValid)
            {
                var criteria = new CustomerCriteria
                {
                    QueryString          = model.q,
                    LastNamePrefix       = model.ln,
                    MinAnniversaryMonth  = model.ams,
                    MaxAnniversaryMonth  = model.ame,
                    MinBirthMonth        = model.bdms,
                    MaxBirthMonth        = model.bdme,
                    MinDateAddedUtc      = model.das,
                    MaxDateAddedUtc      = model.dae,
                    MinDateRegisteredUtc = model.drs,
                    MaxDateRegisteredUtc = model.dre,
                    MinLastOrderDateUtc  = model.lods,
                    MaxLastOrderDateUtc  = model.lode,
                    IsDeleted            = model.d,
                    IsArchived           = model.a,
                    QueryFields          = model.qf,
                    ResultFields         = model.rf,
                    Page                 = model.i - 1,
                    PageSize             = model.s,
                    MinProfileDateUtc    = model.pds,
                    MaxProfileDateUtc    = model.pde
                };

                if (!string.IsNullOrWhiteSpace(model.sf))
                {
                    // REVIEW: Consider updating Quartet SearchModel to have an array of sorts
                    // along with associated sort directions
                    var sorts = model.sf.Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries);
                    criteria.Sort = sorts.Select(s => new Sort { Field = s, Descending = model.sd ?? false }).ToArray();
                }

                var client = _clientFactory.GetCustomerSearchClient();

                var json = client.Search(criteria);

                return ApiHelpers.JsonResponseMessage(json);
            }

            throw ApiHelpers.ServerError(ModelState);
        }
Ejemplo n.º 20
0
 public UpdateCustomer(CustomerCriteria customerCriteria, Guid customerId)
 {
     this.Criteria   = customerCriteria;
     this.CustomerId = customerId;
 }
Ejemplo n.º 21
0
 public InsertCustomer(CustomerCriteria customerCriteria)
 {
     this.Criteria = customerCriteria;
 }
 public IEnumerable <Customer> FindByCriteria(CustomerCriteria criteria)
 {
     return(_mainContext.Customers
            .Where(c => c.Firstname == criteria.Firstname && c.Lastname == criteria.Lastname)
            .ToList());
 }
Ejemplo n.º 23
0
 protected override void InitObjects(bool createNew)
 {
     listObj     = list = GetList <CustomerList>(createNew);
     criteriaObj = criteria = GetCriteria <CustomerCriteria>(createNew);
 }