public GenericActionResult<RoleReturnModel> CreateRole(CreateRoleBindingModel role) { var identityRole = new IdentityRole { Name = role.Name }; var result = this.Create(identityRole); if (result.Succeeded) return new GenericActionResult<RoleReturnModel> { IsSuccess = true, Result = _modelFactory.Create(identityRole) }; else return new GenericActionResult<RoleReturnModel> { IsSuccess = false, Errors = result.Errors }; }
public async Task<IHttpActionResult> Create(CreateRoleBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var role = new IdentityRole { Name = model.Name }; var result = await this.AppRoleManager.CreateAsync(role); if (!result.Succeeded) { return GetErrorResult(result); } Uri locationHeader = new Uri(Url.Link("GetRoleById", new { id = role.Id })); return Created(locationHeader, TheModelFactory.Create(role)); }
public async Task <IHttpActionResult> Create(CreateRoleBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var role = new IdentityRole { Name = model.Name }; var result = await this.AppRoleManager.CreateAsync(role); if (!result.Succeeded) { return(GetErrorResult(result)); } Uri locationHeader = new Uri(Url.Link("GetRoleById", new { id = role.Id })); return(Created(locationHeader, TheModelFactory.Create(role))); }
public async Task <IHttpActionResult> Create(CreateRoleBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var role = new IdentityRole { Name = model.Name }; var result = await RoleManager.CreateAsync(role); if (!result.Succeeded) { return(GetErrorResult(result)); } Uri uri = Url.Request.RequestUri; var rolereturnmodel = ModelFactory.Create <AspNetRolesModel, IdentityRole>(role, uri); return(Created(uri, rolereturnmodel)); }
public GenericActionResult <RoleReturnModel> CreateRole(CreateRoleBindingModel role) { var identityRole = new IdentityRole { Name = role.Name }; var result = this.Create(identityRole); if (result.Succeeded) { return new GenericActionResult <RoleReturnModel> { IsSuccess = true, Result = _modelFactory.Create(identityRole) } } ; else { return new GenericActionResult <RoleReturnModel> { IsSuccess = false, Errors = result.Errors } }; }
public async Task <IHttpActionResult> Create(CreateRoleBindingModel model) { var role = new ApplicationRole { Id = Guid.NewGuid(), Name = model.Name }; var result = await this.RoleManager.CreateAsync(role); if (!result.Succeeded) { return(GetErrorResult(result)); } else { return(Ok(result)); } //Uri locationHeader = new Uri(Url.Link("GetRoleById", new { id = role.Id })); //return Created(locationHeader, role); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var dataContext = HttpContext.Current.GetOwinContext().Get <ApplicationDbContext>()) { using (var trans = dataContext.Database.BeginTransaction(IsolationLevel.ReadCommitted)) { try { var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, Name = createUserModel.Name, //Level = 3, //JoinDate = DateTime.Now.Date, EmailConfirmed = true, }; //var userpeaton = new PeatonUser() //{ // address = createUserModel.address, // addressnumber = createUserModel.addressnumber, // //age = createUserModel.age, // dni = createUserModel.dni, // genre = createUserModel.genre, // idlocation = createUserModel.idlocation, // name = createUserModel.FirstName, // lastname = createUserModel.LastName, // profession = createUserModel.profession, // //profilephoto = Cryptography.Decrypt(createUserModel.profilephoto), // profilephoto =createUserModel.profilephoto, // state = (Int32)StatesEnum.Valid, // Id = user.Id, // birthdate = createUserModel.birthdate, // apartment=createUserModel.apartment, // civilstatus=createUserModel.civilstatus, // floor=createUserModel.floor, // phonenumber = createUserModel.phonenumber //}; //String randomLink = RandomLink.GetRandomLink(); //var confirmregistration = new ConfirmRegistrations() //{ // dateup = DateTime.Now, // Id = user.Id, // state = (Int32)StatesEnum.NotConfirmed, // randomkey = randomLink, // expiredate = DateTime.Now.AddDays(1), //}; var userduplicate = this.AppUserManager.FindByName(user.UserName); if (userduplicate != null) { throw new ApiBusinessException(0002, "Nombre de usuario duplicado", System.Net.HttpStatusCode.BadRequest, "Http"); } userduplicate = this.AppUserManager.FindByEmail(user.Email); if (userduplicate != null) { throw new ApiBusinessException(0003, "Email duplicado", System.Net.HttpStatusCode.BadRequest, "Http"); } //var userdniduplicate = dataContext.PeatonUsers.Where(t => t.dni.Equals(userpeaton.dni)).FirstOrDefault(); //if (userdniduplicate != null) // throw new ApiBusinessException(0004, "Dni duplicado", System.Net.HttpStatusCode.BadRequest, "Http"); //var userdniduplicateplayer = dataContext.PlayerUsers.Where(t => t.dni.Equals(userpeaton.dni)).FirstOrDefault(); //if (userdniduplicateplayer != null) // throw new ApiBusinessException(0004, "Dni duplicado", System.Net.HttpStatusCode.BadRequest, "Http"); var role = new CreateRoleBindingModel() { Name = createUserModel.RoleName }; IdentityResult addUserResult = await this.AppUserManager .CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { trans.Rollback(); return(GetErrorResult(addUserResult)); } IdentityResult addUserToRoleResult = await this.AppUserManager. AddToRoleAsync(user.Id, role.Name); if (!addUserToRoleResult.Succeeded) { trans.Rollback(); return(GetErrorResult(addUserResult)); } //dataContext.PeatonUsers.Add(userpeaton); //dataContext.SaveChanges(); //dataContext.ConfirmRegsitrations.Add(confirmregistration); //dataContext.SaveChanges(); //RegisterUserStateMail registerUserMail = //new RegisterUserStateMail(user.FirstName + " " + user.LastName, user.UserName, randomLink, createUserModel.Password, createUserModel.Email); //new SimpleMail().SendMail(registerUserMail); trans.Commit(); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); } catch (Exception ex) { trans.Rollback(); throw HandlerExceptions.GetInstance().RunCustomExceptions(ex); } } } }
public GenericActionResult <RoleReturnModel> CreateRole(CreateRoleBindingModel role) { return(_userRoleManager.CreateRole(role)); }