예제 #1
0
        public async Task <ActionResult> RegisterFaculty(RegisterFacultyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName      = model.Email,
                    Email         = model.Email,
                    Firstname     = model.Firstname,
                    Lastname      = model.Lastname,
                    DateOfBirth   = model.DateOfBirth,
                    Address1      = model.Address1,
                    Address2      = model.Address2,
                    City          = model.City,
                    Country       = model.Country,
                    Institution   = model.Institution,
                    Program       = model.Program,
                    YearOfJoining = model.YearOfJoining,
                    PhoneNumber   = model.Mobile
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    result = await UserManager.AddToRoleAsync(user.Id, model.RoleeName);

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

                    // 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);
            }
            List <SelectListItem> list = new List <SelectListItem>();

            foreach (var rolee in RoleManager.Roles)
            {
                list.Add(new SelectListItem()
                {
                    Value = rolee.Name, Text = rolee.Name
                });
            }
            ViewBag.Roles = list;
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        public async Task <ActionResult> RegisterFaculty(RegisterFacultyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName      = model.Email,
                    Email         = model.Email,
                    Firstname     = model.Firstname,
                    Lastname      = model.Lastname,
                    DateOfBirth   = model.DateOfBirth,
                    Address1      = model.Address1,
                    Address2      = model.Address2,
                    City          = model.City,
                    Country       = model.Country,
                    Institution   = model.Institution,
                    Program       = model.Program,
                    YearOfJoining = model.YearOfJoining,
                    PhoneNumber   = model.Mobile,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    result = await UserManager.AddToRoleAsync(user.Id, model.RoleeName);

                    ViewBag.FacultySuccess = "Successfully Created " + user.Firstname + "as a faculty member.";

                    SalaryStructure structure = (SalaryStructure)db.SalaryStructures.First(m => m.Id == model.StructId);

                    var salary = new Salary
                    {
                        Username   = model.Email,
                        Role       = model.RoleeName,
                        BaseSalary = structure.BaseSalary,
                        PayWidth   = structure.PayWidth,
                        MinPay     = structure.MinPay,
                        MaxPay     = structure.MaxPay,
                        Allowance  = structure.Allowance,
                        Housing    = structure.Housing,
                        Medicals   = structure.Medicals,
                        Tax        = structure.Tax,
                        Pension    = structure.Pension,
                        NetSalary  = structure.NetSalary,
                        StructId   = structure.Id
                    };

                    db.Salaries.Add(salary);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "ViewUser"));
                }
                AddErrors(result);
            }
            List <SelectListItem> list = new List <SelectListItem>();

            foreach (var rolee in RoleManager.Roles)
            {
                list.Add(new SelectListItem()
                {
                    Value = rolee.Name, Text = rolee.Name
                });
            }
            list.RemoveRange(4, 2);
            ViewBag.Roles    = list;
            ViewBag.StructId = new SelectList(db.SalaryStructures, "Id", "Role", model.StructId);
            //ViewBag.Ranks = new SelectList(db.FacultyRanks, "Id", "Rank");

            return(View(model));
        }