Пример #1
0
        public IActionResult AddStudent(Student S, IFormFile Cv)
        {
            string     WwwRoot       = _ENV.WebRootPath;
            string     FTPpath       = WwwRoot + "/WebData/Cv";
            string     UniqueName    = Guid.NewGuid().ToString();
            string     FileExtension = Path.GetExtension(Cv.FileName);
            FileStream Fs            = new FileStream(FTPpath + UniqueName + FileExtension, FileMode.Create);

            Cv.CopyTo(Fs);
            Fs.Close();
            S.Cv = "/WebData/Cv" + UniqueName + FileExtension;
            _ORM.Add(S);
            _ORM.SaveChanges();
            string APIURL = "http://bulksms.com.pk/api/sms.php?username=923316125207&password=9178&sender=BrandName&mobile=923349931854&message= Welcome to our website.";

            using (var APIClient = new HttpClient())
            {
                Task <HttpResponseMessage> RM = APIClient.GetAsync(APIURL);
                Task <string> FinalRespone    = RM.Result.Content.ReadAsStringAsync();
            }
            ModelState.Clear();

            MailMessage Obj = new MailMessage();

            Obj.From = new MailAddress("*****@*****.**");
            Obj.To.Add(new MailAddress(S.Email));
            Obj.Subject = "Welcome to theta Solution:";
            Obj.Body    = "Dear" + S.Name + "<br ><br >" +
                          "Thanks for registration with Theta Solution";
            Obj.IsBodyHtml = true;
            if (!string.IsNullOrEmpty(S.Cv))
            {
                Obj.Attachments.Add(new Attachment(_ENV.WebRootPath + S.Cv));
            }
            SmtpClient SMTP = new SmtpClient();

            SMTP.Host        = "*****@*****.**";
            SMTP.Port        = 587;
            SMTP.EnableSsl   = true;
            SMTP.Credentials = new System.Net.NetworkCredential("*****@*****.**", "programer");
            try
            {
                SMTP.Send(Obj);
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Mail has sent successfully";
            }
            ViewBag.Message = "New student has added to list";
            return(View());
        }
Пример #2
0
        public IActionResult AddStudent(Student S, IFormFile Cv)

        {
            string     WwwRoot       = _ENV.WebRootPath;
            string     FTPpath       = WwwRoot + "/WebData/Cv";
            string     UniqueName    = Guid.NewGuid().ToString();
            string     FileExtension = Path.GetExtension(Cv.FileName);
            FileStream Fs            = new FileStream(FTPpath + UniqueName + FileExtension, FileMode.Create);

            Cv.CopyTo(Fs);
            Fs.Close();
            S.Cv = "/WebData/Cv" + UniqueName + FileExtension;

            _ORM.Add(S);
            _ORM.SaveChanges();

            ModelState.Clear();
            MailMessage oEmail = new MailMessage();

            oEmail.From = new MailAddress("*****@*****.**");
            oEmail.To.Add(new MailAddress(S.Email));
            //oEmail.CC.Add(new MailAddress("*****@*****.**"));
            oEmail.Subject = "Thanks for Regisration";
            oEmail.Body    = "Dear " + S.Name + ",<br><br>" +
                             "Thanks for registering with ABC, We are glad to have you in our system." +
                             "<br><br>" +
                             "<b>Regards</b>,<br>ABC Team";
            oEmail.IsBodyHtml = true;
            if (!string.IsNullOrEmpty(S.Cv))
            {
                oEmail.Attachments.Add(new Attachment(WwwRoot + S.Cv));
            }


            SmtpClient oSMTP = new SmtpClient();

            oSMTP.Host        = "smtp.gmail.com";
            oSMTP.Port        = 465;
            oSMTP.EnableSsl   = true;
            oSMTP.Credentials = new System.Net.NetworkCredential("*****@*****.**", "programer");
            try
            {
                oSMTP.Send(oEmail);
            }
            catch (Exception ex)
            {
            }
            //
            ViewBag.Message = "Student Record has been added";
            return(View());
        }
Пример #3
0
        public ActionResult Student_Reg([Bind(Include = "Acc,Password,Checkpwd,Codeimg")] Register regmodel)
        {
            if (regmodel.Codeimg != Session["ValidateCode"].ToString())
            {
                ModelState.AddModelError("", "验证码不正确");
                return(View(regmodel));
            }
            if (ModelState.IsValid)
            {
                string pwd = Tools.MD5Encrypt32(regmodel.Password);
                string acc = regmodel.Acc;

                try
                {
                    var sacc = db.StudentAccs.Where(s => s.StuAcc == acc).FirstOrDefault();

                    if (sacc == null)
                    {
                        StudentAcc stuacc = new StudentAcc {
                            StuAcc = acc, Password = pwd, Time = DateTime.Now
                        };
                        try
                        {
                            db.Configuration.ValidateOnSaveEnabled    = false;
                            db.Configuration.AutoDetectChangesEnabled = false;
                            db.StudentAccs.Add(stuacc);
                            db.SaveChanges();
                            Session["Acc"]     = stuacc.StuAcc;
                            Session["Student"] = true;
                            return(RedirectToAction("Index", "Home"));
                        }
                        catch (Exception e)
                        {
                            Response.Write(e.Message);
                        }
                        finally
                        {
                            db.Configuration.ValidateOnSaveEnabled    = true;
                            db.Configuration.AutoDetectChangesEnabled = true;
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('用户名已经存在!');</script>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
            return(View());
        }