public ActionResult TransactionHistoryReport(FormCollection form) { if (Session["LogedUserID"] != null) { try { var doctors = (from d in db.Doctors where d.firstName != null && d.lastName != null select new DocConsultationReport { doctorid = d.doctorID, firstName = d.firstName, lastName = d.lastName }).ToList(); var patients = (from d in db.Patients where d.firstName != null && d.lastName != null select new PatConsultationReport { patientid = d.patientID, firstName = d.firstName, lastName = d.lastName }).ToList(); ViewBag.Doctors = doctors; ViewBag.Patients = patients; var datefrom = Request.Form["datefrom"].ToString().Trim(); var dateto = Request.Form["dateto"].ToString().Trim(); var doctorid = Request.Form["sltDoctor"].ToString(); var patientid = Request.Form["sltPatient"].ToString(); ViewBag.doctorid = doctorid; ViewBag.patientid = patientid; string fromdateString = datefrom.Trim(); string todateString = dateto.Trim(); string format = "dd/MM/yyyy"; CultureInfo provider = CultureInfo.InvariantCulture; DateTime fd = DateTime.ParseExact(fromdateString, format, provider); DateTime td = DateTime.ParseExact(todateString, format, provider); if (doctorid == "0" && patientid != "0") { var doc = db.SP_selectTransactionHistory(fd, td, Convert.ToInt32(patientid), null); return(View("TransactionHistory", doc)); } if (doctorid != "0" && patientid == "0") { var doc = db.SP_selectTransactionHistory(fd, td, null, Convert.ToInt32(doctorid)); return(View("TransactionHistory", doc)); } if (doctorid != "0" && patientid != "0") { var doc = db.SP_selectTransactionHistory(fd, td, Convert.ToInt32(patientid), Convert.ToInt32(doctorid)); return(View("TransactionHistory", doc)); } var docc = db.SP_selectTransactionHistory(fd, td, null, null); return(View("TransactionHistory", docc)); } catch (Exception ex) { ViewBag.errorMessage = ex.Message; return(View("TransactionHistory")); } } else { return(RedirectToAction("AdminLogin", "Account")); } }