Ejemplo n.º 1
0
        public ActionResult Add()
        {
            var helperBo = new HelperBo();
            // tìm danh sách khách hàng
            var listCustomers = helperBo.SelectWhere(null, "customer", null, null);
            var list          = new List <CustomerDto>();

            if (listCustomers.success && listCustomers.data.Count > 0)
            {
                // tìm tích kê theo của từng khách hàng
                var curDate = DateUtils.FormatYYYYMMDD(DateTime.Now.ToShortDateString());
                foreach (var customer in listCustomers.data)
                {
                    var c = new CustomerDto();
                    c.ID           = customer.ID;
                    c.NAME         = customer.NAME;
                    c.NUMBER_PHONE = customer.NUMBER_PHONE;
                    c.TYPE         = customer.TYPE;
                    c.AGE          = customer.AGE.ToString();
                    c.ADDRESS      = customer.ADDRESS;

                    var listTichKe = helperBo.SelectWhere(null, "contract", "DATE>='" + curDate + "' and CUSTOMER_ID=" + customer.ID, null);
                    if (listTichKe.success && listTichKe.data.Count > 0)
                    {
                        List <ContractDto> listContract = new List <ContractDto>();
                        foreach (var contract in listTichKe.data)
                        {
                            var Contract = new ContractDto()
                            {
                                CUSTOMER_ID = contract.CUSTOMER_ID,
                                DATE        = contract.DATE,
                                ID          = contract.ID,
                                PRODUCT_ID  = contract.PRODUCT_ID,
                                RATIO       = contract.RATIO,
                                TYPE        = contract.TYPE
                            };
                            listContract.Add(Contract);
                        }
                        c.SetList(listContract);
                        list.Add(c);
                    }
                }
            }
            return(View(list));
        }