public ActionResult Create([Bind(Include = "leaveRequestID,employeeID,allDayEvent,startTime,endTime,leaveReasonID,Description,deliveryManagerID,departmentManagerID")] EmployeeLeaveRequestViewModel employeeLeaveRequestViewModel)
        {
            LeaveRequest newLeaveRequest = new LeaveRequest
            {
                allDayEvent = employeeLeaveRequestViewModel.allDayEvent,
                deliveryManager = employeeLeaveRequestViewModel.deliveryManager,
                deliveryManagerComment = employeeLeaveRequestViewModel.deliveryManagerComment,
                deliveryManagerStatus = GetRequestStatusByName("Pending"),
                departmentManager = employeeLeaveRequestViewModel.departmentManager,
                departmentManagerComment = employeeLeaveRequestViewModel.departmentManagerComment,
                departmentManagerStatus = GetRequestStatusByName("Pending"),
                Description = employeeLeaveRequestViewModel.Description,
                employee = employeeLeaveRequestViewModel.employee,
                endTime = employeeLeaveRequestViewModel.endTime,
                leaveReason = employeeLeaveRequestViewModel.leaveReason,
                leaveReasonID = employeeLeaveRequestViewModel.leaveReasonID,
                startTime = employeeLeaveRequestViewModel.startTime,
                deliveryManagerID = employeeLeaveRequestViewModel.deliveryManagerID,
                departmentManagerID = employeeLeaveRequestViewModel.departmentManagerID,
                employeeID = employeeLeaveRequestViewModel.employeeID,

            };

            if (ModelState.IsValid)
            {

                db.LeaveRequests.Add(newLeaveRequest);
                db.SaveChanges();

                return RedirectToAction("Index");
            }

            // ViewBag.leaveReasonID = new SelectList(db.LeaveReasons, "leaveReasonID", "leaveReasonName", employeeLeaveRequestViewModel.leaveReasonID);
            //ViewBag.requestStatusID = new SelectList(db.RequestStatus, "requestStatusID", "requestStatusName", employeeLeaveRequestViewModel.requestStatusID);
            return View(employeeLeaveRequestViewModel);
        }
        private LeaveRequest mapLeaveRequestViewModel(EmployeeLeaveRequestViewModel leaveRequestViewModel)
        {
            var emp = db.Employees.Find(leaveRequestViewModel.employeeID);
            var delMan = db.Employees.Find(leaveRequestViewModel.deliveryManagerID);
            var depMan = db.Employees.Find(leaveRequestViewModel.departmentManagerID);
            var lreason = db.LeaveReasons.Find(leaveRequestViewModel.leaveReasonID);

            RequestStatus initStatus = GetRequestStatusByName("Pending");

               // RequestStatus approvedStatus = GetRequestStatusByName("Approved");

            LeaveRequest newLeaveRequst = new LeaveRequest()
            {
                leaveRequestID = leaveRequestViewModel.leaveRequestID,

                employee = emp,
                allDayEvent = leaveRequestViewModel.allDayEvent,
                startTime = leaveRequestViewModel.startTime,
                endTime = leaveRequestViewModel.endTime,
                leaveReason = lreason,
                Description = leaveRequestViewModel.Description,
                deliveryManager = delMan,
                deliveryManagerComment = "",
                departmentManager = depMan,
                departmentManagerComment = "",
                departmentManagerStatus = initStatus,
                deliveryManagerStatus = initStatus

            };

            return newLeaveRequst;
        }
コード例 #3
0
        private void sendMailToDepartmentManager(LeaveRequest leaveRequest)
        {
            //string linkToProcessRequest = getLinkForRequest(leaveRequest.leaveRequestID);
            //Employee employee = db.Employees.Single(e => e.employeeID == leaveRequest.departmentManager.employeeID);
            //string email = employee.employeeEmail;
            //string subject = "New Leave Request";
            //string body = "You have recieved new leave request from:  <i style=\"color: green\">" + leaveRequest.employee.employeeName + "</i> Approved by delivery manager:  <i style=\"color: #FF8000\">" + leaveRequest.deliveryManager.employeeName + "</i><br/>" + getLinkForRequest(leaveRequest.leaveRequestID);

            //string depManagerHTMLBody = getHTMLEmailForDepManager(leaveRequest);

            ////sendMail("*****@*****.**", employee.employeeEmail, subject, body, smtpHost);
            //EmployeeLeaveRequestViewModelsController.sendMailUsingDBSettings(db, email, subject, depManagerHTMLBody);
        }
コード例 #4
0
        private string getHTMLEmailForDepManager(LeaveRequest leaveRequest)
        {
            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\">" + leaveRequest.employee.employeeName + "</i> Approved by delivery manager:  <i style=\"color: #FF8000\">" + leaveRequest.deliveryManager.employeeName + "</i><br/>";
            string buttonText = "Go to request";
            string buttonLink = "http://localhost:9877/DepartmentManagerLeaveRequestViewModels/ProcessRequest/" + leaveRequest.leaveRequestID;

            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 sendMailToDeliveryManager(int deliveryManagerID, LeaveRequest leaveRequest)
        {
            string linkToProcessRequest = getLink(leaveRequest.leaveRequestID);
            Employee employee = db.Employees.Single(e => e.employeeID == deliveryManagerID);
            string email = employee.employeeEmail;
            string subject = "New Leave Request";
            string body = "<h3>You have recieved new leave request from: <i style=\"color: green\">" + leaveRequest.employee.employeeName + "</i> </h3><br/>" + getLink(leaveRequest.leaveRequestID);
            string smtpHost = "smtp.gmail.com";

            string HTMLBody = getHTMLEmail(leaveRequest.employee.employeeName,leaveRequest.leaveRequestID);

            //sendMail("*****@*****.**", employee.employeeEmail, subject, body, smtpHost);
            sendMailUsingDBSettings(db, employee.employeeEmail, subject, HTMLBody);
        }
        public static string ReplacePdfForm(LeaveRequest leaveRequest)
        {
            ////string fileNameExisting = @"\Resources\LeaveRequestTemplate.pdf";
            //string fileNameExisting = "~/Resources/LeaveRequestTemplate.pdf";
            string fileNameNew = Path.GetTempPath()+leaveRequest.employee.employeeName+".pdf";

               // 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", leaveRequest.employee.employeeName);

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

                form.SetFieldProperty("StartTime", "textsize", 8.0f, null);
                form.SetField("StartTime", leaveRequest.allDayEvent ? leaveRequest.startTime.ToShortDateString() : leaveRequest.startTime.ToString());

                form.SetFieldProperty("EndTime", "textsize", 8.0f, null);
                form.SetField("EndTime", leaveRequest.allDayEvent ? leaveRequest.endTime.ToShortDateString() : leaveRequest.endTime.ToString());

                form.SetFieldProperty("LeaveReason", "textsize", 8.0f, null);
                form.SetField("LeaveReason", leaveRequest.leaveReason.leaveReasonName);

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

                form.SetFieldProperty("DeliveryManager", "textsize", 8.0f, null);
                form.SetField("DeliveryManager", leaveRequest.deliveryManager.employeeName);

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

                form.SetFieldProperty("DepartmentManager", "textsize", 8.0f, null);
                form.SetField("DepartmentManager", leaveRequest.departmentManager.employeeName);

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

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

                form.SetFieldProperty("EmployeeSignature", "textsize", 8.0f, null);
                form.SetField("EmployeeSignature", leaveRequest.employee.employeeName);

                form.SetFieldProperty("DeliveryManagerSignature", "textsize", 8.0f, null);
                form.SetField("DeliveryManagerSignature", leaveRequest.deliveryManager.employeeName);

                form.SetFieldProperty("DepartmentManagerSignature", "textsize", 8.0f, null);
                form.SetField("DepartmentManagerSignature", leaveRequest.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;
            }
        }