예제 #1
0
        public ActionResult Create(int? id)
        {
            //if (TempData["UploadedFile"] != null)
            //{
            //    return View(ExtractMsgFile(TempData["UploadedFile"].ToString()));
            //}

            //LoadDdlEmployees();
            //LoadDdlLTypes();
            //LoadDdlReasons();

            //return View();

            Leave leave = new Leave();

            //Create brand new record
            if (id == null)
            {
                if (TempData["UploadedFile"] != null)
                {
                    return View(ExtractMsgFile(TempData["UploadedFile"].ToString()));
                }

                leave.LeaveDate = DateTime.Now;
                LoadDdlEmployees();
                LoadDdlLTypes();
                LoadDdlReasons();

                return View(leave);
            }

            //Copy a record and populate on Create View
            leave = db.Leaves.Find(id);
            if (leave == null)
            {
                return HttpNotFound();
            }

            LoadDdlEmployees(leave.EmployeeID);
            LoadDdlLTypes(leave.LTypeID);
            LoadDdlReasons(leave.ReasonID);

            return View(leave);
        }
예제 #2
0
        private Leave ExtractMsgFile(string UploadedFile)
        {
            string ExtractedFolder = Server.MapPath("~/Temp/" + Guid.NewGuid().ToString() + "/");

            if (!Directory.Exists(ExtractedFolder))
            {
                Directory.CreateDirectory(ExtractedFolder);
            }

            MsgReader.Reader reader = new MsgReader.Reader();
            reader.ExtractToFolder(UploadedFile, ExtractedFolder, false);

            string[] ExtractedFiles = Directory.GetFiles(ExtractedFolder, "*.htm");

            Leave leave = new Leave();

            if (System.IO.File.Exists(ExtractedFiles[0]))
            {
                string MsgContent = System.IO.File.ReadAllText(ExtractedFiles[0]);

                string BreakTag = "<br/>";

                string FromTag = "From:</td><td>";
                string From = MsgContent.Substring(MsgContent.IndexOf(FromTag) + FromTag.Length);
                From = From.Substring(From.IndexOf("&nbsp&lt;") + "&nbsp&lt;".Length);
                From = From.Substring(0, From.IndexOf("&gt;"));

                if (From.ToLower().Contains("cn=recipients"))
                {
                    var emailList = db.Employees.Select(e => e.Email);
                    foreach (var email in emailList)
                    {
                        if (From.ToLower().Contains(email))
                        {
                            From = email;
                            break;
                        }
                    }
                }

                string SentOnTag = "Sent on:</td><td>";
                string SentOn = MsgContent.Substring(MsgContent.IndexOf(SentOnTag) + SentOnTag.Length);
                SentOn = SentOn.Substring(0, SentOn.IndexOf(BreakTag));

                string SubjectTag = "Subject:</td><td>";
                string Subject = MsgContent.Substring(MsgContent.IndexOf(SubjectTag) + SubjectTag.Length);
                Subject = Subject.Substring(0, Subject.IndexOf(BreakTag));

                ViewBag.From = From;
                ViewBag.SentOn = SentOn;
                ViewBag.Subject = Subject;

                leave.LeaveDate = Convert.ToDateTime(SentOn);

                leave.EmployeeID = db.Employees
                                    .Where(x => x.Email == From)
                                    .Select(y => y.ID).FirstOrDefault();

                Directory.Delete(ExtractedFolder, true);
                System.IO.File.Delete(UploadedFile);
            }

            LoadDdlEmployees(leave.EmployeeID);
            LoadDdlLTypes();
            LoadDdlReasons();

            return leave;
        }
예제 #3
0
 private void DisplayReasonDesc(Leave leave)
 {
     ViewBag.ReasonDesc = db.Reasons
                             .Where(x => x.ID == leave.ReasonID)
                             .Select(y => y.Desc).First();
 }
예제 #4
0
 private void DisplayLTypeName(Leave leave)
 {
     ViewBag.LTypeName = db.LTypes
                             .Where(x => x.ID == leave.LTypeID)
                             .Select(y => y.Name).First();
 }
예제 #5
0
 private void DisplayEmployeeName(Leave leave)
 {
     ViewBag.EmployeeName = db.Employees
                             .Where(x => x.ID == leave.EmployeeID)
                             .Select(y => y.LastName + ", " + y.FirstName).First();
 }