public ActionResult DeleteCall(Int32 callID)
        {
            CallLog call = context.CallLogs.Where(m => m.CallID == callID).FirstOrDefault();

            context.CallLogs.Remove(call);
            context.SaveChanges();

            return(RedirectToAction("Index", "Student"));
        }
        public ActionResult Update(StudentModel studentModel)
        {
            Student studentExists = new Student();

            using (var db = new HomeworkHotlineEntities())
            {
                studentExists = GetStudent(studentModel);

                Student newStudent = MapModelToStudent(studentModel);
                if (ModelState.IsValid && studentExists == null)

                {
                    db.Students.Add(newStudent);
                    db.SaveChanges();

                    TempData["studentModel"] = MapStudentToModel(newStudent);
                    if ((bool)TempData["AdminAddStudent"])
                    {
                        return(RedirectToAction("List"));
                    }
                    return(RedirectToAction("Index", "CallLog"));
                }

                ModelState.AddModelError("", "That codename is not available. Please enter a different code name.");
                GetDropdownData();
                return(View("StudentManage"));
            }
        }
Example #3
0
        public ActionResult ConductPayroll([DataSourceRequest] DataSourceRequest request, bool isPayrollForMnps)
        {
            using (var db = new HomeworkHotlineEntities())
            {
                DataSourceResult result = db.TimeEntries.ToDataSourceResult(request);

                List <TimeEntry> timeEntriesList = (List <TimeEntry>)result.Data;
                List <TimeEntry> timeEntries     = timeEntriesList;
                if (isPayrollForMnps)
                {
                    timeEntries = timeEntryService.GetMNPSTimeEntries(timeEntriesList);
                }

                foreach (TimeEntry item in timeEntries)
                {
                    if (item.EndTime != null)
                    {
                        item.IsLocked = true;
                        if (item.PayrollDate == null)
                        {
                            item.PayrollDate = DateTime.Now;
                        }
                    }
                }

                db.SaveChanges();

                return(View());
            }
        }
        public ActionResult GeneratePrizeLetter()
        {
            using (var db = new HomeworkHotlineEntities())
            {
                List <CallLog> callLogs = db.CallLogs
                                          .Where(m => m.PrizeGiven == null && m.PrizeID != null && m.PrizeStudentName != null)
                                          .ToList();

                const int pageMargin   = 50;
                var       doc          = new Document(PageSize.LETTER, pageMargin, pageMargin, pageMargin - 30, pageMargin);
                var       memoryStream = new MemoryStream();
                var       pdfWriter    = PdfWriter.GetInstance(doc, memoryStream);

                doc.Open();

                BaseFont baseFont              = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
                Font     font                  = new Font(baseFont, 10f);
                Font     font_bold             = new Font(baseFont, 10f, Font.BOLD);
                Font     large_font_bold       = new Font(baseFont, 12f, Font.BOLD);
                Font     large_green_font_bold = new Font(baseFont, 12f, Font.BOLD, BaseColor.GREEN);


                int i = 0;
                foreach (CallLog call in callLogs)
                {
                    #region Letter Construction
                    School school = call.Student.School;

                    Paragraph header = new Paragraph();
                    header.Add(Chunk.NEWLINE);
                    header.Add(new Chunk(string.Format("{0}\n", DateTime.Today.ToLongDateString()), font));
                    header.Add(Chunk.NEWLINE);
                    header.Add(new Chunk(string.Format("{0}\n", call.PrizeTeacherName), font));
                    header.Add(new Chunk(string.Format("{0} -- {1}\n", school.SchoolName, school.County.CountyName), font));
                    header.Add(new Chunk(string.Format("{0}\n", school.Address1), font));
                    if (school.Address2 != null)
                    {
                        header.Add(new Chunk(string.Format("{0}\n", school.Address2), font));
                    }
                    header.Add(new Chunk(string.Format("{0}, {1} {2}\n", school.City, school.State, school.Zip), font));

                    header.Add(Chunk.NEWLINE);
                    header.Add(new Chunk(string.Format("Dear {0} and Parent or Guardian,\n", call.PrizeStudentName), font));
                    header.Add(new Chunk("Thank you for calling Homework Hotline and working so hard!  We know homework can be difficult, but the best students are those who ask questions when they don't understand and who practice the skills and concepts they are learning.  You're doing both, and the teachers at Homework Hotline are proud of your efforts.  Keep up the great work and feel free to reach out to our certified teachers whenever you need help!  We hope you enjoy your prize!", font));
                    header.Add(Chunk.NEWLINE);

                    Paragraph letter = new Paragraph();
                    letter.Add(Chunk.NEWLINE);
                    letter.Add(new Chunk("Do your friends need help too?  Tell them to call ", font_bold));
                    letter.Add((new Chunk("615-298-6636", font_bold)).SetUnderline(1, -3));
                    letter.Add(new Chunk(" or chat with us through ", font_bold));
                    letter.Add((new Chunk("homeworkhotline.info", font_bold)).SetUnderline(1, -3));
                    letter.Add(new Chunk(" for help, and ", font_bold));
                    letter.Add((new Chunk("YOU", font_bold)).SetUnderline(1, -3));
                    letter.Add(new Chunk(" will receive an additional prize!", font_bold));
                    letter.Add(Chunk.NEWLINE);
                    letter.Alignment = iTextSharp.text.Image.ALIGN_CENTER;

                    Paragraph list = new Paragraph();
                    list.Add((new Chunk("Here's how:", font_bold)).SetUnderline(1, -3));
                    iTextSharp.text.List how_list = new iTextSharp.text.List(iTextSharp.text.List.ORDERED);
                    how_list.Add(new ListItem("Tell your friends to call or chat with Homework Hotline when they have homework questions or need tutoring.", font));
                    how_list.Add(new ListItem("Have them tell us your code name and that you told them to call us for help.", font));
                    how_list.Add(new ListItem("We will send you an extra prize the next time you call for tutoring.  Just tell us your friends called!", font));
                    list.Add(how_list);

                    list.Add(Chunk.NEWLINE);
                    list.Add(new Chunk("You should be proud of the work you are doing; we definitely are!", font));
                    list.Add(Chunk.NEWLINE);

                    Paragraph closing = new Paragraph();
                    closing.Add(Chunk.NEWLINE);
                    closing.Add(new Chunk(string.Format("{0}\n", "Sincerely yours,"), font));
                    Image signature = Image.GetInstance(Server.MapPath("~/Images/Signature.png"));
                    signature.ScalePercent(45);
                    closing.Add(signature);
                    closing.Add(new Chunk(string.Format("{0}\n", "Rebekah Vance"), font));
                    closing.Add(new Chunk(string.Format("{0}\n", "Executive Director"), font));
                    closing.Add(new Chunk(string.Format("{0}\n", "Homework Hotline"), font));
                    closing.Add(Chunk.NEWLINE);

                    Paragraph ps = new Paragraph();
                    ps.Add(new Chunk("P.S. If you enjoyed our services, we'd appreciate your review! Our teachers want to know how they're doing. To review us, Google: Homework Hotline. Then, on your phone you'll scroll and hit \"more about Homework Hotline.\"  You should see the stars to rate us.  Thank you!", font));
                    ps.Add(Chunk.NEWLINE);

                    Paragraph footer = new Paragraph();
                    footer.Add(Chunk.NEWLINE);
                    footer.Add(new Chunk("Homework Hotline is Tennessee’s source for FREE ", large_font_bold));
                    footer.Add(new Chunk("homework help", large_green_font_bold).SetUnderline(1, -3));
                    footer.Add(new Chunk(" and ", large_font_bold));
                    footer.Add(new Chunk("tutoring", large_green_font_bold).SetUnderline(1, -3));
                    footer.Add(new Chunk(" over the phone and online!", large_font_bold));
                    footer.Add(Chunk.NEWLINE);
                    footer.Alignment = iTextSharp.text.Image.ALIGN_CENTER;

                    PdfPTable codename_table = new PdfPTable(1);
                    codename_table.WidthPercentage    = 100f;
                    codename_table.DefaultCell.Border = 0;
                    PdfPCell cell = new PdfPCell();
                    cell.Border = 0;
                    Paragraph contents = new Paragraph();
                    contents.Alignment = Element.ALIGN_RIGHT;
                    contents.Add(new Chunk(call.Student.CodeName, font));
                    cell.AddElement(contents);
                    codename_table.AddCell(cell);

                    Image header_logo = Image.GetInstance(Server.MapPath("~/Images/hhLogo.png"));
                    header_logo.ScaleToFit(260f, 280f);
                    header_logo.Alignment = iTextSharp.text.Image.ALIGN_CENTER;

                    if (i > 0)
                    {
                        doc.NewPage();
                    }
                    doc.Add(header_logo);
                    doc.Add(header);
                    doc.Add(letter);
                    doc.Add(list);
                    doc.Add(closing);
                    doc.Add(ps);
                    doc.Add(footer);
                    doc.Add(codename_table);

                    call.PrizeGiven = DateTime.Now;

                    i++;
                    #endregion
                }

                db.SaveChanges();

                pdfWriter.CloseStream = false;
                doc.Close();
                memoryStream.Position = 0;
                string handle = Guid.NewGuid().ToString();
                TempData[handle] = memoryStream.ToArray();
                string filename = "PrizeLetters" + (DateTime.Now.ToShortDateString()).Replace("/", "") + ".pdf";
                return(new JsonResult()
                {
                    Data = new { FileGuid = handle, FileName = filename }
                });

                ////          Dictionary<string, string> _replacePatterns = new Dictionary<string, string>()
                ////            {
                ////// TODO: format CallDate

                ////      { "DATE", date },
                ////      { "TEACHER_NAME", clm.PrizeTeacherName },
                ////      { "SCHOOL_NAME", schoolModel.SchoolName },
                ////      { "COUNTY", schoolModel.CountyName },
                ////      { "ADDRESS", schoolModel.Address1 + " " + schoolModel.Address2 },
                ////      { "CITY", schoolModel.City },
                ////      { "STATE", schoolModel.State },
                ////      { "ZIP", schoolModel.Zip },
                ////      { "STUDENT_NAME", clm.PrizeStudentName },
                ////      { "CODE_NAME", student.CodeName },
                ////            };

                //string fileName = "PrizeLetter_Template.docx";
                //string fileDownloadName = "PrizeLetter_Template.docx";
                //var filepath = System.IO.Path.Combine(Server.MapPath("/Documents/"), fileName);
                //var fileDownloadPath = System.IO.Path.Combine(Server.MapPath("/Documents/"), fileName);
                ////     string fileDownloadName = String.Format("PrizeLetter_{0}.docx", student.CodeName);
                ////     var fileDownloadPath = System.IO.Path.Combine(Server.MapPath("/Documents/"), fileDownloadName);

                //// replace text in docx with above values
                //using (DocX document = DocX.Load(filepath))
                //{
                //    // Check if all the replace patterns are used in the loaded document.
                //    if (document.FindUniqueByPattern(@"<[\w \=]{4,}>", RegexOptions.IgnoreCase).Count == _replacePatterns.Count)
                //    {
                //        // Do the replacement
                //        for (int i = 0; i < _replacePatterns.Count; ++i)
                //        {
                //            document.ReplaceText("<(.*?)>", ReplaceFunc, false, RegexOptions.IgnoreCase, null, new Formatting());
                //        }

                //        // TODO: not saving....
                //        // Save this document to disk.
                //        document.SaveAs(fileDownloadPath);
                //        //     Console.WriteLine("\tCreated: ReplacedText.docx\n");
                //    }
                //}
                //// end replace text

                ////return File(filepath, MimeMapping.GetMimeMapping(filepath), fileDownloadName);
                //return File(fileDownloadPath, MimeMapping.GetMimeMapping(fileDownloadPath), fileDownloadName);
            }
        }