Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,IDDivisionProgram,Recommendations,ActionNeeded,ResponsibleOfficePerson,ResponsibleEmail,Resources,TimeFrame,OverseeingPerson,Eveidences")] Recommendation recommendation, HttpPostedFileBase Filepost, HttpPostedFileBase Filepost1, HttpPostedFileBase Filepost2, HttpPostedFileBase Filepost3)
        {
            if (ModelState.IsValid)
            {
                Employee employee = db.Employees.Where(e => e.Email == User.Identity.Name).Include(o => o.RoleQualityAudit).FirstOrDefault();

                ViewBag.AtachFile = employee.RoleQualityAudit.AtachFile;
                string filePath = null;
                string PathFile = null;

                if (Filepost != null)
                {
                    if (Filepost.ContentLength > 0)
                    {
                        string pathfile = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID));
                        if (!Directory.Exists(pathfile))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(pathfile);
                        }

                        filePath = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID), Path.GetFileName(Filepost.FileName));
                        Filepost.SaveAs(filePath);
                        PathFile = "/Uploads/" + employee.MemberID + "/" + Path.GetFileName(Filepost.FileName);
                    }
                }
                if (Filepost1 != null)
                {
                    if (Filepost1.ContentLength > 0)
                    {
                        string pathfile = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID));
                        if (!Directory.Exists(pathfile))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(pathfile);
                        }

                        filePath = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID), Path.GetFileName(Filepost1.FileName));
                        Filepost1.SaveAs(filePath);
                        PathFile += "|Uploads/" + employee.MemberID + "/" + Path.GetFileName(Filepost1.FileName);

                    }
                }
                if (Filepost2 != null)
                {
                    if (Filepost2.ContentLength > 0)
                    {
                        string pathfile = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID));
                        if (!Directory.Exists(pathfile))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(pathfile);
                        }

                        filePath = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID), Path.GetFileName(Filepost2.FileName));
                        Filepost2.SaveAs(filePath);
                        PathFile += "|Uploads/" + employee.MemberID + "/" + Path.GetFileName(Filepost2.FileName);

                    }
                }
                if (Filepost3 != null)
                {
                    if (Filepost3.ContentLength > 0)
                    {
                        string pathfile = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID));
                        if (!Directory.Exists(pathfile))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(pathfile);
                        }

                        filePath = Path.Combine(Server.MapPath("../../Uploads/" + employee.MemberID), Path.GetFileName(Filepost3.FileName));
                        Filepost3.SaveAs(filePath);
                        PathFile += "|Uploads/" + employee.MemberID + "/" + Path.GetFileName(Filepost3.FileName);

                    }
                }
                recommendation.Eveidences = PathFile;
                db.Entry(recommendation).State = EntityState.Added;
                db.Recommendations.Add(recommendation);
                db.SaveChanges();
                Message message = new Message();
                message.Destination = recommendation.ResponsibleEmail;
                message.Body = "test no attach";
                message.Subject = "test no attach";
                string test = IdentityConfig.SendAsync(message);
                return RedirectToAction("Index");
            }

            ViewBag.OverseeingPerson = new SelectList(db.Overseeings, "ID", "Name", recommendation.OverseeingPerson);
            ViewBag.Resources = new SelectList(db.Resources, "ID", "Name", recommendation.Resources);
            ViewBag.ResponsibleOfficePerson = new SelectList(db.ResponsibleOffices, "ID", "Name", recommendation.ResponsibleOfficePerson);
            return View(recommendation);
        }
Exemplo n.º 2
0
        public void UserSendMail()
        {
            DateTime date = DateTime.Now;
            var recommendations = db.Recommendations.Where(o => o.TimeFrame > date);
            Message message = new Message();
            foreach (Recommendation recom in recommendations)
            {

                DateTime timeframe = (DateTime)recom.TimeFrame;
                TimeSpan Time = (TimeSpan)(timeframe.Subtract(date));
                int TongSoNgay = Time.Days;
                if (TongSoNgay == 30)
                {
                    message.Body = "recommendations  30 days";
                }
                else if (TongSoNgay == 15)
                {
                    message.Body = "recommendations  15 days";
                }
                else if (TongSoNgay == 5)
                {
                    message.Body = "recommendations  5 days";
                }
                else if (TongSoNgay == 0)
                {
                    message.Body = "recommendations 1 days";
                }
                else {
                    continue;
                }
                message.Destination =  recom.ResponsibleEmail;
                message.Subject = "Wanning";
                message.Attach = AppPath.ApplicationPath + "Reports/Recommendations.pdf";
                string test = IdentityConfig.SendAsync(message);
            }

            var Nqf = db.ResponsibleRegistrations.Where(o => o.ReviewDate > date);

            foreach (ResponsibleRegistration NQF in Nqf)
            {

                DateTime timeframe = (DateTime)NQF.ReviewDate;
                TimeSpan Time = (TimeSpan)(timeframe.Subtract(date));
                int TongSoNgay = Time.Days;
                if (TongSoNgay == 180)
                {
                    message.Body = "NQF  180 days";
                }
                else if (TongSoNgay == 90)
                {
                    message.Body = "NQF  90 days";
                }
                else if (TongSoNgay == 60)
                {
                    message.Body = "NQF  60 days";
                }
                else if (TongSoNgay == 30)
                {
                    message.Body = "NQF 30 days";
                }
                else if (TongSoNgay == 15)
                {
                    message.Body = "NQF 15 days";
                }
                else
                {
                    continue;
                }
                Array email = NQF.Emails.Split('|');
                foreach (string em in email){
                    message.Destination = em;
                    message.Subject = "Wanning";
                    message.Attach = AppPath.ApplicationPath + "Reports/ResponsibleAccreditation.pdf";
                    string test = IdentityConfig.SendAsync(message);
                }
            }
            var Acc = db.ResponsibleAccreditations.Where(o => o.ReviewDate > date);

            foreach (ResponsibleAccreditation ac in Acc)
            {

                DateTime timeframe = (DateTime)ac.ReviewDate;
                TimeSpan Time = (TimeSpan)(timeframe.Subtract(date));
                int TongSoNgay = Time.Days;
                if (TongSoNgay == 180)
                {
                    message.Body = "Accreditation  180 days";
                }
                else if (TongSoNgay == 90)
                {
                    message.Body = "Accreditation  90 days";
                }
                else if (TongSoNgay == 60)
                {
                    message.Body = "Accreditation  60 days";
                }
                else if (TongSoNgay == 30)
                {
                    message.Body = "Accreditation 30 days";
                }
                else if (TongSoNgay == 15)
                {
                    message.Body = "Accreditation 15 days";
                }
                else
                {
                    continue;
                }
                Employee employee = db.Employees.Where(o => o.MemberID == ac.MemberID).FirstOrDefault();
                message.Destination = employee.Email;
                message.Subject = "Wanning";
                message.Attach = AppPath.ApplicationPath + "Reports/ResponsibleAccreditation.pdf";
                string test = IdentityConfig.SendAsync(message);
            }
        }