示例#1
0
        public IActionResult SendCode(int Code)
        {
            var log = new StudentLog
            {
                dateTime = DateTime.Now
            };
            Students student = NstudentRepository.GetStudentByCode(Code);

            var webRoot    = _env.WebRootPath;
            var pathToFile = _env.WebRootPath
                             + Path.DirectorySeparatorChar.ToString()
                             + "mail"
                             + Path.DirectorySeparatorChar.ToString()
                             + "RegisterMail.html";
            var builder = new BodyBuilder();

            using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }
            string messageBody = string.Format(builder.HtmlBody, student.FullName, Code, DateTime.Now.ToString("dddd, d MMMM yyyy HH:mm:ss"));


            BackgroundJob.Schedule(() => Reminder(student.Id), TimeSpan.FromDays(1));

            _mail.GenMail(student.email, "Tack för din registrering! ", messageBody);

            // return RedirectToAction("Index", "Home", new { Ncode = student.code });

            log.Message = "New User with email: " + student.email + " Registered and got the code:" + student.code;
            NstudentRepository.AddLog(log);
            return(RedirectToAction("Index", "Home", new { userName = student.email }));
        }