Ejemplo n.º 1
0
 /// <summary>
 /// Renders a partial MVC view to string. Use this method to render
 /// a partial view that doesn't merge with _Layout and doesn't fire
 /// _ViewStart.
 /// </summary>
 /// <param name="viewPath">
 /// The path to the view to render. Either in same controller, shared by
 /// name or as fully qualified ~/ path including extension
 /// </param>
 /// <param name="model">The model to pass to the viewRenderer</param>
 /// <param name="controllerContext">Active controller context</param>
 /// <param name="errorMessage">optional output parameter to receive an error message on failure</param>
 /// <returns>String of the rendered view or null on error</returns>
 public static string RenderPartialView(string viewPath, object model,
                                        ControllerContext controllerContext,
                                        out string errorMessage)
 {
     errorMessage = null;
     try
     {
         ViewRenderer renderer = new ViewRenderer(controllerContext);
         return(renderer.RenderPartialView(viewPath, model));
     }
     catch (Exception ex)
     {
         errorMessage = ex.GetBaseException().Message;
     }
     return(null);
 }
Ejemplo n.º 2
0
        public Stream GenerateUserCV(Employee employee,
                                     ControllerContext ControllerContext)
        {
            //string generatedPDFHtml = this.RenderView("PdfCVGenerator", employee, ViewData);
            string generatedPDFHtml = ViewRenderer.RenderView("~/Views/Employees/PdfCVGenerator.cshtml", employee,
                                                              ControllerContext);
            //generating the header
            string headertext = ViewRenderer.RenderView("~/Views/Employees/PdfCVHeader.cshtml", employee,
                                                        ControllerContext);

            byte[] pdfBuffer = PdfGenerator.ConvertHtmlToPDF(generatedPDFHtml, headertext);

            Stream stream = new MemoryStream(pdfBuffer);

            return(stream);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  //we'll get the email addresses and notify the attendants the attendants
        /// </summary>
        public void SendMeetingRequest(RATV3Entities db,
                                       Event ev,
                                       List <Employee> attendantEmployees,
                                       Employee creator,
                                       ControllerContext ControllerContext,
                                       int update = 0)
        {
            try
            {
                //getting the reviewed employee
                Attendant at       = ev.Attendants.FirstOrDefault();
                Employee  reviewed = db.Employees.Where(x => x.EmployeeID == at.EmployeeID).FirstOrDefault();
                reviewed.SkillLevelsList = reviewed.SkillLevels.ToList();

                //getting message content
                EventTypeInfo currentEventType = Const.EventTypesinfo.Where(x => x.EventType == ev.EventType).FirstOrDefault();
                string        embededHtml      = "<html><head></head><body>" + "<p>Test</p>" + "<br/><br/>" + "<p>Test Embeded</p>" + "<br/>" + "<p>Test Ending</p>" + "<br/></body></html>";

                if (currentEventType != null && currentEventType.EventType == "Performance Review")
                {
                    string generatednotificationHTML = ViewRenderer.RenderView("~/Views/Notifications/PerformanceReview.cshtml", reviewed,
                                                                               ControllerContext);

                    if (!String.IsNullOrEmpty(generatednotificationHTML))
                    {
                        embededHtml = generatednotificationHTML;
                    }
                }



                //preping the email message
                MailMessage email = new MailMessage();
                email.From = new MailAddress(creator.Email, creator.FirstName + ' ' + creator.LastName);
                //adding recipients
                foreach (Employee attendant in attendantEmployees)
                {
                    email.To.Add(new MailAddress(attendant.Email, attendant.FirstName + ' ' + attendant.LastName));
                }

                email.IsBodyHtml = true;
                email.Subject    = ev.EventType;


                //preparing email content
                //"text/html" - this view will have all the content
                System.Net.Mime.ContentType htmlMimeContent = new System.Net.Mime.ContentType("text/html");
                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(embededHtml, htmlMimeContent);
                htmlView.ContentType.CharSet = Encoding.UTF8.WebName;
                if (ev.EventType == "Performance Review" && ev.Attendants != null && ev.Attendants.Count > 0 && reviewed != null)
                {
                    //we'll attach the pdf to the email

                    Stream pdfDocument = GenerateUserCV(reviewed, ControllerContext);
                    if (pdfDocument != null)
                    {
                        LinkedResource resource = new LinkedResource(pdfDocument);
                        resource.ContentType.Name = reviewed.FirstName + " " + reviewed.LastName + " " + "Report.pdf";
                        htmlView.LinkedResources.Add(resource);
                    }
                }
                else if (ev.EventType == "Department Monthly Meeting" && reviewed.DepartmentID.HasValue)
                {
                    //we'll attach the excel report to the email

                    byte[] array = ExcelReportGenerator.GenerateExcelReportForDepartment(reviewed.DepartmentID.Value,
                                                                                         ev.StartTime.Month, ev.StartTime.Year, db);
                    Stream excelDocument = new MemoryStream(array);
                    if (excelDocument != null)
                    {
                        LinkedResource resource = new LinkedResource(excelDocument);
                        resource.ContentType.Name = "Department Report.xlsx";
                        htmlView.LinkedResources.Add(resource);
                    }
                }



                //preparing calendar meeting view
                DateTime endTime;
                if (ev.EndTime.HasValue)
                {
                    endTime = ev.EndTime.Value;
                }
                else
                {
                    endTime = ev.StartTime;
                }

                //this is the guid of the meeting request
                Guid requestGUID;

                if (ev.IcsGuid.HasValue)
                {
                    requestGUID = ev.IcsGuid.Value;
                }
                else
                {
                    requestGUID = Guid.NewGuid();
                }
                AlternateView avCal = CreateICSView(email, ev.StartTime, endTime, ev, requestGUID, update);
                //email.Headers.Add("Content-class", "urn:content-classes:calendarmessage");
                email.AlternateViews.Add(htmlView);
                email.AlternateViews.Add(avCal);

                //finally we send the mail
                client.Send(email);

                if (!ev.IcsGuid.HasValue)
                {
                    ev.IcsGuid         = requestGUID;
                    db.Entry(ev).State = EntityState.Modified;
                }
                if (update > 0)
                {
                    //we want to be able to store the update number too

                    //ev.UpdateNo = update;
                    db.Entry(ev).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                //handle Exception
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  //we'll get the email addresses and notify the attendants about the event being canceled
        /// </summary>
        public void CancelMeetingRequest(RATV3Entities db,
                                         Event ev,
                                         List <Employee> attendantEmployees,
                                         Employee creator,
                                         ControllerContext ControllerContext)
        {
            //getting the reviewed employee
            Attendant at       = ev.Attendants.FirstOrDefault();
            Employee  reviewed = db.Employees.Where(x => x.EmployeeID == at.EmployeeID).FirstOrDefault();

            reviewed.SkillLevelsList = reviewed.SkillLevels.ToList();


            string embededHtml = ViewRenderer.RenderView("~/Views/Notifications/CanceledEvent.cshtml", reviewed,
                                                         ControllerContext);

            if (String.IsNullOrEmpty(embededHtml))
            {
                embededHtml = " This Event has been canceled";
            }
            //preping the email message
            var email = new MailMessage();

            email.From = new MailAddress(creator.Email, creator.FirstName + ' ' + creator.LastName);
            //adding recipients
            foreach (Employee attendant in attendantEmployees)
            {
                email.To.Add(new MailAddress(attendant.Email, attendant.FirstName + ' ' + attendant.LastName));
            }

            email.IsBodyHtml = true;
            email.Subject    = ev.EventType;


            //preparing email content
            //"text/html" - this view will have all the content
            System.Net.Mime.ContentType htmlMimeContent = new System.Net.Mime.ContentType("text/html");
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(embededHtml, htmlMimeContent);

            htmlView.ContentType.CharSet = Encoding.UTF8.WebName;

            //preparing calendar meeting view
            DateTime endTime;

            if (ev.EndTime.HasValue)
            {
                endTime = ev.EndTime.Value;
            }
            else
            {
                endTime = ev.StartTime;
            }

            //this is the guid of the meeting request
            Guid requestGUID;

            if (ev.IcsGuid.HasValue)
            {
                //if we have
                requestGUID = ev.IcsGuid.Value;
                AlternateView avCal = CreateCancelationICSView(email, ev.StartTime, endTime, ev, requestGUID);
                //email.Headers.Add("Content-class", "urn:content-classes:calendarmessage");
                email.AlternateViews.Add(htmlView);
                email.AlternateViews.Add(avCal);

                //finally we send the mail
                client.Send(email);
            }
        }