Пример #1
0
 public ActionResult DeleteConfirmed(string id)
 {
     Microsoft.AspNet.Identity.EntityFramework.IdentityRole role = db.Roles.Find(id);
     db.Roles.Remove(role);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Пример #2
0
        public async Task <ActionResult> RegisterPatient(CustomerRegisterPatient model)
        {
            if (ModelState.IsValid)
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                var user = new Domain.Entities.Patient {
                    UserName = model.Email, Email = model.Email, cin = model.cin, firstName = model.firstName, lastName = model.lastName, PhoneNumber = model.PhoneNumber, gender = model.gender, Address = model.Address, RoleUser = "******"
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                //if (result.Succeeded)
                //{
                //    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                //    // For more information on how to enable account confirmation and password reset please visit http://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("Confirmation", "PatientAppointement");
                //}

                PatientAppointementController patientCont = new PatientAppointementController();
                //patientCont.Create().
                //AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Confirmation", "PatientAppointement"));
        }
Пример #3
0
        public async Task <ActionResult> Edit(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
        {
            try
            {
                if (string.IsNullOrEmpty(role.Name.Trim()))
                {
                    throw new InvalidOperationException("Role Name can not be empty");
                }
                role.Name = role.Name.Trim();
                context.Entry(role).State = System.Data.Entity.EntityState.Modified;
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                var sb = new System.Text.StringBuilder();
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        sb.AppendFormat("{0}", validationError.ErrorMessage);
                    }
                }
                ViewBag.ResultMessage = $"Unable to update the Role. Reason is { sb.ToString() }";
            }
            catch (Exception ex)
            {
                ViewBag.ResultMessage = $"Unable to update the Role. Reason is { ex.GetBaseException().Message }";
            }
            return(View());
        }
Пример #4
0
        /// <summary>
        /// 从账号池中分配随机账号
        /// </summary>
        /// <returns></returns>
        public string GetRandomUserNumber()
        {
            Random r1    = new Random();
            int    count = db.UserNumbers.Count(u => u.State == (int)EnumState.未使用);

            if (count > 0)
            {
                int index = r1.Next(0, count);
                var user  = db.UserNumbers.Where(u => u.State == (int)EnumState.未使用).OrderBy(u => u.UserId).Skip(count - 1).FirstOrDefault();
                return(user.UserId);
            }
            else if (db.UserNumbers.Count() == 0)
            {
                UserNumber newuser = new UserNumber()
                {
                    UserId = "Admin", State = (int)EnumState.未使用
                };
                db.UserNumbers.Add(newuser);
                if (!RoleManager.RoleExists("Admin"))
                {
                    Microsoft.AspNet.Identity.EntityFramework.IdentityRole role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole("Admin");
                    RoleManager.Create(role);
                }
                db.SaveChanges();
                return("Admin");
            }
            else
            {
                return(null);
            }
        }
        private ApplicationUser CreateUser()
        {
            var user = new ApplicationUser
            {
                UserName       = _installModel.Email,
                Email          = _installModel.Email,
                RegisterDate   = DateTime.Now,
                RegisterIP     = HttpContext.Current.Request.GetVisitorIP(),
                LastAccessDate = DateTime.Now,
                LastAccessIP   = HttpContext.Current.Request.GetVisitorIP()
            };

            using (var context = new ApplicationDbContext())
            {
                context.Database.Initialize(true);
                context.SaveChanges();

                var userManager = new ApplicationUserManager(new Microsoft.AspNet.Identity.EntityFramework.UserStore <ApplicationUser>(context));

                // Create role/user and redirect
                var userRole   = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(Enum_UserType.Administrator.ToString());
                var roleResult = RoleManager.Create(userRole);
                var result     = userManager.Create(user, _installModel.Password);
                var roleAdded  = userManager.AddToRole(user.Id, Enum_UserType.Administrator.ToString());
            }

            return(user);
        }
Пример #6
0
        public ActionResult Create(FormCollection collection)
        {
            if (string.IsNullOrEmpty(collection["roleName"]))
            {
                return(RedirectToAction("Index"));
            }
            try
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = collection["roleName"];

                using (var context = ApplicationDbContext.Create())
                {
                    context.Roles.Add(role);

                    context.SaveChanges();
                    ViewBag.ResultMessage = "Role created successfully !";
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
Пример #7
0
        public override System.Web.Mvc.ActionResult Edit(Microsoft.AspNet.Identity.EntityFramework.IdentityRole Role)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Edit);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Role", Role);
            EditOverride(callInfo, Role);
            return(callInfo);
        }
Пример #8
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.PTTID, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false); //, rememberBrowser: false

                    // 如需如何進行帳戶確認及密碼重設的詳細資訊,請前往 https://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    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, "驗證您的Email帳戶", "請按一下此連結驗證您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>");

                    //角色名稱
                    var roleName = "Member"; // (model.PTTID != "某ID") ?  "Member" :

                    //判斷角色是否存在
                    if (RoleManager.RoleExists(roleName) == false)
                    {
                        //角色不存在,建立角色
                        var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(roleName);
                        await RoleManager.CreateAsync(role);
                    }
                    //將使用者加入該角色
                    await UserManager.AddToRoleAsync(user.Id, roleName);

                    string ipAddress = string.Empty;
                    if (!String.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"]))
                    {
                        ipAddress = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"];
                    }
                    else
                    {
                        ipAddress = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    }

                    //發送專屬序號
                    await Task.Run(() => SendBase5UserId(model.PTTID, user.Id, ipAddress));



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

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return(View(model));
        }
        public ActionResult Edit(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
        {
            try {
                context.Entry(role).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();

                return(RedirectToAction("Index"));
            } catch {
                return(View());
            }
        }
        public override void CreateRole(string roleName)
        {
            var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
            role.Id = Guid.NewGuid().ToString();
            role.Name = roleName;

            using (var usersContext = new ApplicationDbContext())
            {
                usersContext.Roles.Add(role);
                usersContext.SaveChanges();
            }
        }
        public ActionResult Edit([Bind(Include = "Id,Name")] Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
        {
            if (ModelState.IsValid)
            {
                db.Entry(role).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
Пример #12
0
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // 從外部登入提供者處取得使用者資訊
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Birthday = model.Birthday, Gender = model.Gender, Country = model.Country, City = model.City, Phone = model.Phone
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        //前台角色名稱
                        var RoleName = "Member";
                        //後台角色名稱
                        //var RoleName = "Admin";

                        if (HttpContext.GetOwinContext().Get <ApplicationRoleManager>().RoleExists(RoleName) == false)
                        {
                            //角色不存在,建立角色
                            var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(RoleName);
                            await HttpContext.GetOwinContext().Get <ApplicationRoleManager>().CreateAsync(role);
                        }
                        //將使用者加入該角色
                        await UserManager.AddToRoleAsync(user.Id, RoleName);

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

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Пример #13
0
 // GET: Roles/Delete/5
 public ActionResult Delete(string id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Microsoft.AspNet.Identity.EntityFramework.IdentityRole role = db.Roles.Find(id);
     if (role == null)
     {
         return(HttpNotFound());
     }
     return(View(role));
 }
Пример #14
0
        public ActionResult Create(Role role)
        {
            Microsoft.AspNet.Identity.EntityFramework.IdentityRole rol = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
            rol.Name = role.RoleName;
            if (ModelState.IsValid)
            {
                db.Roles.Add(rol);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
        public override void CreateRole(string roleName)
        {
            var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();

            role.Id   = Guid.NewGuid().ToString();
            role.Name = roleName;

            using (var usersContext = new ApplicationDbContext())
            {
                usersContext.Roles.Add(role);
                usersContext.SaveChanges();
            }
        }
Пример #16
0
        // In this method we will create default User roles and Admin user for login   
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
            var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));


            // In Startup iam creating first Admin Role and creating a default Admin User    
            if (!roleManager.RoleExists("Admin"))
            {

                // first we create Admin rool   
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website                  

                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email = "*****@*****.**";

                string userPWD = "J0670928458";

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin   
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");

                }
            }

            // creating Creating Manager role    
            if (!roleManager.RoleExists("Manager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Manager";
                roleManager.Create(role);

            }

            // creating Creating Player role    
            if (!roleManager.RoleExists("Player"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Player";
            }
}
Пример #17
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Country   = model.Country,
                    City      = model.City,
                    Gender    = model.Gender,
                    Birthday  = model.Birthday,
                    Phone     = model.Phone
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // 如需如何進行帳戶確認及密碼重設的詳細資訊,請前往 https://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    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, "確認您的帳戶", "請按一下此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>");

                    //前台角色名稱
                    var RoleName = "Member";
                    //後台角色名稱
                    //var RoleName = "Admin";

                    if (HttpContext.GetOwinContext().Get <ApplicationRoleManager>().RoleExists(RoleName) == false)
                    {
                        //角色不存在,建立角色
                        var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(RoleName);
                        await HttpContext.GetOwinContext().Get <ApplicationRoleManager>().CreateAsync(role);
                    }
                    //將使用者加入該角色
                    await UserManager.AddToRoleAsync(user.Id, RoleName);

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

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return(View(model));
        }
 public ActionResult Delete(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
 {
     try
     {
         // TODO: Add delete logic here
         var MyRole = db.Roles.Find(role.Id);
         db.Roles.Remove(MyRole);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(role));
     }
 }
Пример #19
0
        public void CreateRole(string roleName)
        {
            try {
                var role = db.Roles.SingleOrDefault(x => x.Name == roleName);

                if (role == null)
                {
                    role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(roleName);
                    db.Roles.Add(role);
                    db.SaveChanges();
                }
            }
            catch {
                // do nothing
            }
        }
Пример #20
0
        public async Task <ActionResult> RegisterMember(CustomerRegisterMember model, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                var user = new Domain.Entities.Member
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    cin         = model.cin,
                    firstName   = model.firstName,
                    lastName    = model.lastName,
                    PhoneNumber = model.PhoneNumber,
                    gender      = model.gender,
                    Address     = model.Address,
                    password2   = model.Password,
                    imagePath   = imagePath.FileName,
                    RoleUser    = "******"
                };



                imagePath.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), imagePath.FileName));


                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://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("HomeManager", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("RegisterMember", "Account"));
        }
 public ActionResult Edit(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
 {
     try
     {
         Db.Entry(role).State = System.Data.Entity.EntityState.Modified;
         Db.SaveChanges();
         TempData["UserMessage"] = "Role Updated Successfully.";
         TempData["Title"]       = "Success.";
         return(RedirectToAction("Index"));
     }
     catch
     {
         TempData["UserMessage"] = "Update is Unsuccessful, Please try again later.";
         TempData["Title"]       = "Error.";
         return(View());
     }
 }
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            ApplicationUser user = new ApplicationUser()
            {
                FirstName = model.FirstName, LastName = model.LastName, UserName = model.Email, Email = model.Email
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }
            else
            {
                if (model.IsGuestUser)
                {
                    ApplicationDbContext db = new ApplicationDbContext();
                    Microsoft.AspNet.Identity.EntityFramework.IdentityRole role = db.Roles.FirstOrDefault(x => x.Name == "Guest");
                    var loginuser = db.Users.FirstOrDefault(x => x.Id == user.Id);
                    if (role == null)
                    {
                        role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Guest"
                        };
                        db.Roles.Add(role);
                    }

                    var userRole = new Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole
                    {
                        UserId = user.Id,
                        RoleId = role.Id
                    };

                    loginuser.Roles.Add(userRole);
                    db.SaveChanges();
                }
            }
            return(Ok());
        }
        private ApplicationUser CreateUser()
        {
            var user = new ApplicationUser
            {
                UserName       = _installModel.Email,
                FirstName      = "Administrator",
                Email          = _installModel.Email,
                EmailConfirmed = true,
                Currency       = _installModel.Currency,
                RegisterDate   = DateTime.Now,
                RegisterIP     = HttpContext.Current.Request.GetVisitorIP(),
                LastAccessDate = DateTime.Now,
                LastAccessIP   = HttpContext.Current.Request.GetVisitorIP(),
                Rating         = 4
            };

            using (var context = new ApplicationDbContext())
            {
                context.Database.Initialize(true);
                context.SaveChanges();

                var userManager = new ApplicationUserManager(new Microsoft.AspNet.Identity.EntityFramework.UserStore <ApplicationUser>(context));

                // Create Roles
                foreach (var role in Enum.GetValues(typeof(Enum_UserRole)))
                {
                    var userRole   = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(role.ToString());
                    var roleResult = RoleManager.Create(userRole);
                }

                // Create default user role and redirect

                var result    = userManager.Create(user, _installModel.Password);
                var roleAdded = userManager.AddToRole(user.Id, Enum_UserRole.Administrator.ToString());
            }

            // Copy profile image
            var pathFrom = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/images/sample/profile"), "admin.jpg");
            var pathTo   = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/images/profile"), string.Format("{0}.{1}", user.Id, "jpg"));

            File.Copy(pathFrom, pathTo, true);

            return(user);
        }
Пример #24
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, NickName = model.NickName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // 如需如何啟用帳戶確認和密碼重設的詳細資訊,請造訪 http://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    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, "確認您的帳戶", "請按一下此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>");

                    //角色名稱
                    var roleName = "Normal";  //預設為Normal

                    //判斷角色是否存在
                    if (HttpContext.GetOwinContext().Get <ApplicationRoleManager>().RoleExists(roleName) == false)
                    {
                        //角色不存在,建立角色
                        var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(roleName);
                        await HttpContext.GetOwinContext().Get <ApplicationRoleManager>().CreateAsync(role);
                    }
                    //將使用者加入該角色
                    await UserManager.AddToRoleAsync(user.Id, roleName);


                    ViewData["SuccessMessage"] = "請至 mailbox 確認";
                    return(View(model));
                }
                AddErrors(result);
            }


            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return(View(model));
        }
        public ActionResult Create(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
        {
            try
            {
                // TODO: Add insert logic here

                if (ModelState.IsValid)
                {
                    db.Roles.Add(role);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(role));
            }
            catch
            {
                return(View());
            }
        }
Пример #26
0
 public ActionResult EditRole(Microsoft.AspNet.Identity.EntityFramework.IdentityRole role)
 {
     try
     {
         db.Entry(role).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         // prepopulat roles for the view dropdown
         var usersList = db.Users.OrderBy(r => r.UserName).ToList().Select(rr => new SelectListItem {
             Value = rr.UserName.ToString(), Text = rr.UserName
         }).ToList();
         ViewBag.Users = usersList;
         var list = db.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem {
             Value = rr.Name.ToString(), Text = rr.Name
         }).ToList();
         ViewBag.Roles = list;
         return(RedirectToAction("ShowRoles", db.Roles.OrderBy(o => o.Name).ToList()));
     }
     catch (Exception e)
     {
         Log.Error(e);
         return(RedirectToAction("ShowRoles", db.Roles.OrderBy(o => o.Name).ToList()));
     }
 }
Пример #27
0
        public ActionResult Create(ApplicationRoleModel model)
        {
            if (ModelState.IsValid)
            {
                var newRole = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                newRole.Name = model.Name;
                db.Roles.Add(newRole);

                var result = db.SaveChanges();
                if (result > 0)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Role can not save!");
                }

                return(RedirectToAction("Edit", new { Id = newRole.Id }));
            }

            return(View(model));
        }
Пример #28
0
 partial void EditOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, Microsoft.AspNet.Identity.EntityFramework.IdentityRole Role);