public ActionResult Create(Role role) { if (ModelState.IsValid) { AccountServices.CreateNew<Role>(role); return RedirectToAction("Index"); } return View(role); }
public override void CreateRole(string roleName) { if (string.IsNullOrEmpty(roleName)) { throw CreateArgumentNullOrEmptyException("roleName"); } using (BlogUnitOfWork context = new BlogUnitOfWork(new ModelContextInit())) { dynamic role = context.Roles.FirstOrDefault(Rl => Rl.RoleName == roleName); if (role != null) { throw new InvalidOperationException(string.Format("Role exists: {0}", roleName)); } Role NewRole = new Role { RoleId = Guid.NewGuid(), RoleName = roleName }; context.Roles.Add(NewRole); context.SaveChanges(); } }