public JsonResult Register(RegisterUserViewModel viewModel) { if (!ModelState.IsValid) return Json(new JsonResponse("Invalid Data", "Please provide correct details for page")); if (WebSecurity.UserExists(viewModel.UserName)) { return Json(new JsonResponse("User exists Already!", "A user with same username already exists")); } WebSecurity.CreateUserAndAccount(viewModel.UserName, viewModel.Password, propertyValues: new { FirstName = viewModel.FirstName, LastName = viewModel.LastName, IsActive = viewModel.IsActive, CreateDate = DateTime.Now } ); if (!Roles.RoleExists("Admin")) { Roles.CreateRole("Admin"); } Roles.AddUserToRole(viewModel.UserName, "Admin"); var lstUserModel = GetListingModel(); return Json(new JsonResponse( new { UserList = RenderPartialViewToString("List", lstUserModel) }) { Message = "User Added Successfully!", Description = "New User has been added succesfully." }); }
public JsonResult Register() { var viewModel = new RegisterUserViewModel(); var viewAdd = RenderPartialViewToString("Register", viewModel); return Json(new JsonResponse((object)viewAdd), JsonRequestBehavior.AllowGet); }