Exemplo n.º 1
0
        // GET: Trainees/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trainee trainee = db.Trainees.Find(id);

            if (trainee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID        = new SelectList(db.Accounts, "ID", "Username", trainee.ID);
            ViewBag.TrainerID = new SelectList(db.Trainers, "TrainerID", "Name", trainee.TrainerID);
            return(View(trainee));
        }
Exemplo n.º 2
0
        public ActionResult UpdateDetails(Trainee traineeInput)
        {
            var currentUserId = User.Identity.GetUserId();

            var traineeDetail = _context.Users
                                .OfType <Trainee>()
                                .SingleOrDefault(t => t.Id == currentUserId);

            traineeDetail.UserName              = traineeInput.UserName;
            traineeDetail.Age                   = traineeInput.Age;
            traineeDetail.Education             = traineeInput.Education;
            traineeDetail.PhoneNumber           = traineeInput.PhoneNumber;
            traineeDetail.Date_of_birth         = traineeInput.Date_of_birth;
            traineeDetail.Department            = traineeInput.Department;
            traineeDetail.Exp_details           = traineeInput.Exp_details;
            traineeDetail.Location              = traineeInput.Location;
            traineeDetail.Main_programming_lang = traineeInput.Main_programming_lang;
            traineeDetail.TOEIC_score           = traineeInput.TOEIC_score;


            _context.SaveChanges();

            return(RedirectToAction("Index", "Manage"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (User.IsInRole("Admin"))
                {
                    if (model.RoleName == "Staff")
                    {
                        if (_context.Users.OfType <Staff>().Any(t => t.Email.Contains(model.Email) || t.UserName.Contains(model.Email)))
                        {
                            ViewData["PostState"] = "Staff has been registered before!";
                            return(View(model));
                        }
                        var user = new Staff()
                        {
                            UserName = model.Email, Email = model.Email
                        };
                        var result = await UserManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            result = await UserManager.AddToRoleAsync(user.Id, "Staff");

                            // 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>");
                            ViewData["PostState"] = "Staff has been created successfully!";
                            return(RedirectToAction("StaffAccountView", "Admin"));
                        }
                        AddErrors(result);
                    }
                    if (model.RoleName == "Trainer")
                    {
                        if (_context.Users.OfType <Trainer>().Any(t => t.Email.Contains(model.Email) || t.UserName.Contains(model.Email)))
                        {
                            ViewBag.ResponseMessage = "Trainer has been registered before!";
                            return(View(model));
                        }
                        var user = new Trainer()
                        {
                            UserName = model.Email, Email = model.Email
                        };
                        var result = await UserManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            result = await UserManager.AddToRoleAsync(user.Id, "Trainer");

                            // 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>");
                            ViewBag.ResponseMessage = "Trainer has been created successfully!";
                            return(RedirectToAction("TrainerAccountView", "Admin"));
                        }
                        AddErrors(result);
                    }
                }
                if (User.IsInRole("Staff"))
                {
                    if (ModelState.IsValid)
                    {
                        if (_context.Users.OfType <Trainee>().Any(t => t.Email.Contains(model.Email) || t.UserName.Contains(model.Email)))
                        {
                            ViewBag.ResponseMessage = "Trainee has been registered before!";
                            return(View(model));
                        }
                        var user = new Trainee()
                        {
                            UserName              = model.Trainee.UserName,
                            Email                 = model.Email,
                            Age                   = model.Trainee.Age,
                            Location              = model.Trainee.Location,
                            Date_of_birth         = model.Trainee.Date_of_birth,
                            Education             = model.Trainee.Education,
                            Main_programming_lang = model.Trainee.Main_programming_lang,
                            TOEIC_score           = model.Trainee.TOEIC_score,
                            Exp_details           = model.Trainee.Exp_details,
                            Department            = model.Trainee.Department
                        };
                        var result = await UserManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            result = await UserManager.AddToRoleAsync(user.Id, "Trainee");


                            // 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>");
                            ViewBag.ResponseMessage = "Trainee has been created successfully!";
                            return(RedirectToAction("TraineeAccountView", "Staff"));
                        }
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.ResponseMessage = "User has been registered before!";
            return(View(model));
        }