private string getHTMLEmailForDepManager(LeaveRequestInfo info, LeaveRequestDescription desc)
        {
            StreamReader reader = new StreamReader(Server.MapPath("~/Content/MailTemplate.html"));
            string email = reader.ReadToEnd();

            string notHeader = "You have new leave request";
            string textHeader = "";
            string textMessage = "You have recieved new leave request from:  <i style=\"color: green\">" + info.Employee.EmployeeName + "</i> Approved by delivery manager:  <i style=\"color: #FF8000\">" + desc.DeliveryManager.EmployeeName + "</i><br/>";
            string buttonText = "Go to request";

            string buttonLink = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "DepartmentManagerLeaveRequestViewModels/ProcessRequest/" + info.LeaveRequestInfoID;

            email = email.Replace("[NotificationHeader]", notHeader);
            email = email.Replace("[TextHeader]", textHeader);
            email = email.Replace("[TextMessage]", textMessage);
            email = email.Replace("[ButtonText]", buttonText);
            email = email.Replace("[ButtonLink]", buttonLink);

            return email;
        }
 private void sendMailToDepartmentManager(LeaveRequestInfo info, LeaveRequestDescription desc)
 {
     Employee employee = db.Employees.Single(e => e.EmployeeID == desc.DepartmentManager.EmployeeID);
     string email = employee.EmployeeEmail;
     string subject = "New Leave Request";
     string depManagerHTMLBody = getHTMLEmailForDepManager(info, desc);
     EmployeeLeaveRequestViewModelsController.sendMailUsingDBSettings(db, email, subject, depManagerHTMLBody);
 }
 private void sendMailToDelManRequestUpdated(LeaveRequestInfo info,LeaveRequestDescription desc)
 {
     Employee employee = db.Employees.Single(e => e.EmployeeID == desc.DeliveryManager.EmployeeID);
     string email = employee.EmployeeEmail;
     string subject = "Request Updated";
     string HTMLBody = getHTMLEmailForRequestUpdate(info.Employee.EmployeeName, info.LeaveRequestInfoID);
     sendMailUsingDBSettings(db, employee.EmployeeEmail, subject, HTMLBody);
 }
        public static string ReplacePdfForm(LeaveRequestInfo info, LeaveRequestDescription desc)
        {
            string dt = DateTime.Now.ToString().Replace('/', ' ').Replace(':', ' ');
            // string fileNameNew = System.AppDomain.CurrentDomain.BaseDirectory +@"\Resources\\"+info.Employee.EmployeeName+" "+dt+".pdf".Replace(' ', '_');

            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\LeaveManagerPDF\";

            bool exists = Directory.Exists(path);

            if (!exists)
            {
                Directory.CreateDirectory(path);
            }

            string fileNameNew = path + info.Employee.EmployeeName + " " + dt + ".pdf".Replace(' ', '_');

            // using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
            using (var newFileStream = new FileStream(fileNameNew, FileMode.Create))
            {
                // Open existing PDF
                var pdfReader = new PdfReader(Properties.Resources.LeaveRequestTemplatePDF);

                // PdfStamper, which will create
                var stamper = new PdfStamper(pdfReader, newFileStream);

                var form = stamper.AcroFields;
                form.GenerateAppearances = true;
                var fieldKeys = form.Fields.Keys;

                //setting font size and setting field text
                form.SetFieldProperty("Employee", "textsize", 8.0f, null);
                form.SetField("Employee",info.Employee.EmployeeName);

                form.SetFieldProperty("AllDayEvent", "textsize", 8.0f, null);
                form.SetField("AllDayEvent", desc.AllDayEvent ? "YES" : "NO");

                form.SetFieldProperty("StartTime", "textsize", 8.0f, null);
                form.SetField("StartTime", desc.AllDayEvent ? desc.StartTime.ToShortDateString() : desc.StartTime.ToString());

                form.SetFieldProperty("EndTime", "textsize", 8.0f, null);
                form.SetField("EndTime", desc.AllDayEvent ? desc.EndTime.ToShortDateString() : desc.EndTime.ToString());

                form.SetFieldProperty("LeaveReason", "textsize", 8.0f, null);
                form.SetField("LeaveReason",desc.LeaveReason.LeaveReasonName);

                form.SetFieldProperty("LeaveDescription", "textsize", 8.0f, null);
                form.SetField("LeaveDescription", desc.Description);

                form.SetFieldProperty("DeliveryManager", "textsize", 8.0f, null);
                form.SetField("DeliveryManager", desc.DeliveryManager.EmployeeName);

                form.SetFieldProperty("DeliveryManagerComment", "textsize", 8.0f, null);
                form.SetField("DeliveryManagerComment", desc.DeliveryManagerComment);

                form.SetFieldProperty("DepartmentManager", "textsize", 8.0f, null);
                form.SetField("DepartmentManager", desc.DepartmentManager.EmployeeName);

                form.SetFieldProperty("DepartmentManagerComment", "textsize", 8.0f, null);
                form.SetField("DepartmentManagerComment", desc.DepartmentManagerComment);

                form.SetFieldProperty("CreateDate", "textsize", 8.0f, null);
                form.SetField("CreateDate",desc.CreateDate.ToString());

                form.SetFieldProperty("EmployeeSignature", "textsize", 8.0f, null);
                form.SetField("EmployeeSignature",info.Employee.EmployeeName);

                form.SetFieldProperty("DeliveryManagerSignature", "textsize", 8.0f, null);
                form.SetField("DeliveryManagerSignature",desc.DeliveryManager.EmployeeName);

                form.SetFieldProperty("DepartmentManagerSignature", "textsize", 8.0f, null);
                form.SetField("DepartmentManagerSignature", desc.DepartmentManager.EmployeeName);

                form.SetFieldProperty("Date", "textsize", 8.0f, null);
                form.SetField("Date", DateTime.Now.ToShortDateString());

                // "Flatten" the form so it wont be editable/usable anymore
                stamper.FormFlattening = true;

                stamper.Close();
                pdfReader.Close();
                return fileNameNew;
            }
        }
        private LeaveRequestDescription mapViewModelToLeaveRequestDesc(EmployeeLeaveRequestViewModel leaveRequestViewModel, LeaveRequestInfo newLeaveRequest)
        {
            var delMan = getEmployeeByName(leaveRequestViewModel.DeliveryManagerName);//db.Employees.Find(leaveRequestViewModel.deliveryManagerID);
            var depMan = getEmployeeByName(leaveRequestViewModel.DepartmentManagerName);//db.Employees.Find(leaveRequestViewModel.departmentManagerID);
            var lreason = db.LeaveReasons.Find(leaveRequestViewModel.LeaveReasonID);

            RequestStatus initStatus = GetRequestStatusByName("Pending");

            LeaveRequestDescription lrDescription = new LeaveRequestDescription()
            {

                AllDayEvent = leaveRequestViewModel.AllDayEvent,
                StartTime = leaveRequestViewModel.StartTime,
                EndTime = leaveRequestViewModel.EndTime,
                LeaveReason = lreason,
                Description = leaveRequestViewModel.Description,
                DeliveryManager = delMan,
                DeliveryManagerComment = "",
                DepartmentManager = depMan,
                DepartmentManagerComment = "",
                DepartmentManagerStatus = initStatus,
                DeliveryManagerStatus = initStatus,
                LeaveRequestInfo = newLeaveRequest,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now

            };

            return lrDescription;
        }
        private EmployeeLeaveRequestViewModel mapLeaveRequestToViewModel(LeaveRequestInfo reqInfo, LeaveRequestDescription reqDes)
        {
            return new EmployeeLeaveRequestViewModel()
            {
                AllDayEvent = reqDes.AllDayEvent,
                DeliveryManager = reqDes.DeliveryManager,
                DeliveryManagerComment = reqDes.DeliveryManagerComment,
                DeliveryManagerID = reqDes.DeliveryManager.EmployeeID,
                DeliveryManagerName = reqDes.DeliveryManager.EmployeeName,
                DeliveryManagerStatus = reqDes.DeliveryManagerStatus,
                DepartmentManager = reqDes.DepartmentManager,
                EmployeeName = reqInfo.Employee.EmployeeName,
                Employee = reqInfo.Employee,
                EmployeeID = reqInfo.Employee.EmployeeID,
                DepartmentManagerComment = reqDes.DepartmentManagerComment,
                DepartmentManagerID = reqDes.DepartmentManager.EmployeeID,
                DepartmentManagerName = reqDes.DepartmentManager.EmployeeName,
                DepartmentManagerStatus = reqDes.DepartmentManagerStatus,
                Description = reqDes.Description,
                EndTime = reqDes.EndTime,
                LeaveReason = reqDes.LeaveReason,
                LeaveReasonID = reqDes.LeaveReason.LeaveReasonID,
                LeaveRequestID = reqDes.LeaveRequestInfo.LeaveRequestInfoID,
                StartTime = reqDes.StartTime

            };
        }