コード例 #1
0
        public ActionResult RegisterStu()
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var          temp       = db.Parents.ToList();
            var          tempp      = db.Departments.ToList();
            StuViewModel model      = new StuViewModel()
            {
                Parents     = temp,
                Departments = tempp
            };

            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> RegisterStu(StuViewModel model)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.StudentEmail, Email = model.StudentEmail
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Student");

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    await UserManager.AddToRoleAsync(user.Id, "Student");

                    Student myStu = new Student()
                    {
                        StudentId    = user.Id,
                        FirstName    = model.FirstName,
                        FatherName   = model.FatherName,
                        LastName     = model.LastName,
                        DateOfBirth  = model.DateOfBirth,
                        Gender       = model.Gender,
                        DepartmentId = model.DepartmentId,
                        Address      = model.Address,
                        HomeNumber   = model.HomeNumber,
                        ParentId     = model.ParentId,
                        StudentEmail = model.StudentEmail
                    };
                    db.Students.Add(myStu);
                    db.SaveChanges();
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            model.Departments = db.Departments.ToList();
            model.Parents     = db.Parents.ToList();
            return(View(model));
        }
コード例 #3
0
ファイル: StudentController.cs プロジェクト: hst-web/test
        public JsonResult Edit(StuViewModel model)
        {
            ResultRetrun rmodel = new ResultRetrun();

            if (ModelState.IsValid)
            {
                StuCertificate data = stuService.Get(model.Id);
                data.Number   = model.Number;
                data.Name     = model.StudentName;
                data.Category = model.Category;
                data.State    = (PublishState)model.State;
                data.Gender   = model.Gender;
                data.City     = model.City.ToString();
                data.Province = model.Province < 1 ? Constant.DEFAULT_PROVINCE : model.Province.ToString();
                data.HeadImg  = model.HeadImg;

                rmodel.isSuccess = stuService.Update(data);
            }

            return(Json(rmodel));
        }
コード例 #4
0
ファイル: StudentController.cs プロジェクト: hst-web/test
        public JsonResult Add(StuViewModel model)
        {
            ResultRetrun rmodel = new ResultRetrun();

            if (ModelState.IsValid)
            {
                StuCertificate stuModel = new StuCertificate()
                {
                    Number   = model.Number,
                    Name     = model.StudentName,
                    Category = model.Category,
                    State    = (PublishState)model.State,
                    Gender   = model.Gender,
                    City     = model.City.ToString(),
                    Province = model.Province.ToString(),
                    UserId   = GetAccount().Id,
                    HeadImg  = model.HeadImg
                };
                rmodel.isSuccess = stuService.Add(stuModel);
            }

            return(Json(rmodel));
        }