public ActionResult DiscountFees(StudentSearchViewModel userInput)
        {
            TransactionHelper helper = new TransactionHelper();
            string            error  = "";

            HostelTransactionViewModel viewModel = helper.ConstructViewModelForHostelFeeDiscount(userInput.bid, out error);

            if (viewModel != null)
            {
                // generate the list of account heads to be displayed and add it to the view bag
                ViewBag.acHeadList = new SelectList(helper.GetAccountHeads(), "id", "val");

                // generate the list of payment types to be displayed and add it to the view bag
                ViewBag.paymentTypeList = new SelectList(helper.GetPaymentTypes(true), "id", "val", "4");

                //generate the list of academic years to be displayed and add it to the view bag
                ViewBag.academicYearList = new SelectList(helper.GetValidAcademicYears(viewModel.year), DateTime.Now.Year + "");

                // display the view
                return(PartialView("_AddDiscount", viewModel));
            }

            return(Content(error));
        }
        public ActionResult GenerateStudentReport(StudentSearchViewModel userInput)
        {
            // find the student, if not found, return error
            StudentHelper helper      = new StudentHelper();
            var           studentInfo = helper.GetStudent(userInput.bid);

            if (studentInfo == null)
            {
                ModelState.AddModelError("", "Student not found!");
                return(View(userInput));
            }

            StudentReportDataSet studentDataSet = new StudentReportDataSet();

            // add data to student table
            DataRow myDataRow = studentDataSet.Tables["Student"].NewRow();

            myDataRow["Name"]        = studentInfo.name;
            myDataRow["Sem"]         = studentInfo.semester;
            myDataRow["Gender"]      = studentInfo.Gender1.val;
            myDataRow["Course"]      = studentInfo.Course1.val;
            myDataRow["Branch"]      = studentInfo.Department.val;
            myDataRow["DateOfBirth"] = studentInfo.dob.ToLongDateString();
            studentDataSet.Tables["Student"].Rows.Add(myDataRow);

            // add data to allotment table
            foreach (var allotment in studentInfo.Allotments)
            {
                myDataRow = studentDataSet.Tables["Allotment"].NewRow();
                myDataRow["DateOfJoin"]  = allotment.dateOfJoin.ToLongDateString();
                myDataRow["DateOfLeave"] = allotment.dateOfLeave.HasValue ? allotment.dateOfLeave.Value.ToLongDateString() : "";
                myDataRow["HostelBlock"] = allotment.hostelBlock;
                myDataRow["RoomNumber"]  = allotment.roomNum;
                studentDataSet.Tables["Allotment"].Rows.Add(myDataRow);
            }

            // get data for hostel fee table
            TransactionHelper helper1 = new TransactionHelper();
            Tuple <List <HostelFeeDueViewModel>, Hashtable> result = helper1.GetStudentDues(userInput.bid, true);
            List <HostelFeeDueViewModel> viewModel = result.Item1;

            // add data to hostel fee table
            foreach (var item in viewModel)
            {
                if (item.amount != 0)
                {
                    myDataRow                = studentDataSet.Tables["HostelFee"].NewRow();
                    myDataRow["Year"]        = item.academicYear;
                    myDataRow["Fee Type"]    = item.accountHead;
                    myDataRow["Fee Amount"]  = item.amount;
                    myDataRow["Amount Paid"] = item.amountPaid;
                    myDataRow["Amount Due"]  = item.amountDue;
                    studentDataSet.Tables["HostelFee"].Rows.Add(myDataRow);
                }
            }

            // get data for mess fee table
            List <MessFeeDueViewModel> viewModel1 = helper1.GetMessDue(userInput.bid, true);

            // add data to mess fee table
            foreach (var item in viewModel1)
            {
                myDataRow                = studentDataSet.Tables["MeeFee"].NewRow();
                myDataRow["Year"]        = item.academicYear;
                myDataRow["Month"]       = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(item.month);
                myDataRow["Amount"]      = item.amount;
                myDataRow["Amount Paid"] = item.amountPaid;
                myDataRow["Amount Due"]  = item.amountDue;
                studentDataSet.Tables["MeeFee"].Rows.Add(myDataRow);
            }

            // set data source for the report
            StudentReport studentReport = new StudentReport();

            studentReport.DataSource = studentDataSet;

            // export to pdf, write memory stream to response directly
            using (MemoryStream ms = new MemoryStream())
            {
                PdfExportOptions opts = new PdfExportOptions();
                opts.ShowPrintDialogOnOpen = true;
                studentReport.ExportToPdf(ms, opts);
                ms.Seek(0, SeekOrigin.Begin);
                byte[] report = ms.ToArray();
                Response.ContentType = "application/pdf";
                Response.Clear();
                Response.OutputStream.Write(report, 0, report.Length);
                Response.End();
            }

            return(null);
        }