Ejemplo n.º 1
0
        public ActionResult Index([Bind(Include = "SearchCode, CustomerId, ProjectId,  StartDate,  EndDate")] InvoiceFillter fillter)
        {
            ViewBag.SearchCode = fillter.SearchCode;
            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", fillter.CustomerId);
            ViewBag.ProjectId  = new SelectList(db.Projects, "ProjectId", "Code", fillter.ProjectId);
            ViewBag.StartDate  = fillter.StartDate;
            ViewBag.endDate    = fillter.EndDate;

            var invoice = invoiceRepository.GetAll(fillter);

            return(View(invoice.ToList()));
        }
Ejemplo n.º 2
0
        public IEnumerable <Invoice> GetAll(InvoiceFillter fillter)
        {
            var invoices = _DbContext.Invoices.Include(i => i.Customer).Include(i => i.Project).Include(i => i.InvoiceProducts).AsQueryable();

            if (!string.IsNullOrEmpty(fillter.SearchCode))
            {
                invoices = invoices.Where(i => i.Code == fillter.SearchCode.ToUpper());
            }
            if (!string.IsNullOrEmpty(fillter.ProjectId))
            {
                int qqqq = int.Parse(fillter.ProjectId);
                invoices = invoices.Where(i => i.ProjectId == qqqq);
            }
            if (!string.IsNullOrEmpty(fillter.CustomerId))
            {
                int qqqq = int.Parse(fillter.CustomerId);
                invoices = invoices.Where(i => i.CustomerId == qqqq);
            }
            if (!String.IsNullOrEmpty(fillter.StartDate))
            {
                if (!String.IsNullOrEmpty(fillter.EndDate))
                {
                    DateTime ddStart = DateTime.ParseExact(fillter.StartDate, "yyyy-MM-dd", null);
                    DateTime ddEnd   = DateTime.ParseExact(fillter.EndDate, "yyyy-MM-dd", null);
                    ddEnd    = ddEnd.AddDays(1);
                    invoices = invoices.Where(cb => cb.InvoiceDate >= ddStart && cb.InvoiceDate < ddEnd);
                }
                else
                {
                    //on selected day
                    DateTime ddStart = DateTime.ParseExact(fillter.StartDate, "yyyy-MM-dd", null);
                    DateTime ddEnd   = ddStart.AddDays(1);
                    invoices = invoices.Where(cb => cb.InvoiceDate >= ddStart && cb.InvoiceDate < ddEnd);
                }
            }

            return(invoices.ToList());
        }