//public ActionResult GenerateDisbursementList(string deptId) //{ // DateTime cutoff = DateTime.Now.Date; //Ensures that orders only up to yesterday 2359 is taken into consideration // List<DisbursementDetail> disbursementdetails = new List<DisbursementDetail>(); // Disbursement dis = new Disbursement(); // using (db) // { // var resultSet = from rd in db.RequestDetail // from r in db.Request // where (r.Status.Contains("New") || r.Status.Contains("Outstanding")) // && r.RequestId == rd.RequestId && r.DeptId == deptId // && r.ReqDate < cutoff // group rd by new { rd.ProductId, r.DeptId } into g // select new DisbursementDetailViewModel//Note to self: Groupby only works with enums or primitive data types // { // ProductId = g.Key.ProductId, // DepartmentId = g.Key.DeptId, // Quantity = g.Sum(x => x.ReqQty) // }; // List<DisbursementDetailViewModel> consolidatedOrders = resultSet.ToList(); // dis = new Disbursement // { // DisDate = DateTime.Now, // Status = "Pending" // //Field for department appears to be missing // //dis.StoreStaff = null; // }; // foreach (DisbursementDetailViewModel p in consolidatedOrders) // { // DisbursementDetail dd = new DisbursementDetail // { // ProductId = p.ProductId, // //RequiredQty = p.Quantity // ReceivedQty = 0, //Should set to zero // DisId = dis.DisId // }; // disbursementdetails.Add(dd); // } // db.Disbursement.Add(dis); // db.DisbursementDetail.AddRange(disbursementdetails); // db.SaveChanges(); // } // return RedirectToAction("DetailedDisbursementList", new { id = dis.DisId }); //} public ActionResult FindDisbursementList(string deptId, string startDate, string endDate) { List <Department> departments = departmentDAO.GetDepartments(); List <Disbursement> disbursements = new List <Disbursement>(); if (deptId != null) { disbursements = disbursementDAO.GetDisbursements(deptId); } if (startDate != null && endDate != null) { disbursements = disbursementDAO.GetDisbursements(DateTime.Parse(startDate), DateTime.Parse(endDate)); } ViewData["departments"] = departments; ViewData["disbursements"] = disbursements; return(View()); }