public async Task <RoleForListDto> AddRoleToUser(int userId, int roleId) { var userRole = await userRoleDal.GetAsync(x => x.UserId == userId && x.RoleId == roleId); if (userRole != null) { throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.AlreadyExist }); } var role = await roleDal.GetAsync(x => x.Id == roleId); if (role == null) { throw new RestException(HttpStatusCode.BadRequest, new { RolesListNotFound = Messages.RoleListNotFound }); } var user = await userDal.GetAsync(x => x.Id == userId); if (user == null) { throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = Messages.UserNotFound }); } var userrole = new UserRole { UserId = user.Id, RoleId = role.Id }; await userRoleDal.Add(userrole); return(mapper.Map <Role, RoleForListDto>(role)); }
public async Task <UserForDetailedDto> Register(UserForRegisterDto userForRegisterDto) { var userForCreate = mapper.Map <User>(userForRegisterDto); byte[] passwordHash, passwordSalt; authHelper.CreatePasswordHash(userForRegisterDto.Password, out passwordHash, out passwordSalt); userForCreate.PasswordHash = passwordHash; userForCreate.PasswordSalt = passwordSalt; var userExist = await userDal.UserExist(userForCreate.Email); if (userExist) { throw new Exception("This Email address is already registered.!!"); } var saveUser = await userDal.Add(userForCreate); if (saveUser == null) { throw new Exception("Could not registered.!!"); } var addDefaultRole = new UserRole() { UserId = userForCreate.Id, RoleId = 1 }; var addRoles = await userRoleDal.Add(addDefaultRole); if (addRoles == null) { throw new Exception("User created but cant added"); } var userToReturn = mapper.Map <UserForDetailedDto>(userForCreate); return(userToReturn); }
public IResult AddWorker(Worker worker) { try { worker.HireDate = DateTime.Now; worker.QuitDate = new DateTime(1900, 01, 01, 0, 0, 0); _workerDal.Add(worker); var userRole = new UserRole { RoleId = 2, //worker rolü UserId = worker.WorkerId }; var oldRole = _userRoleDal.Get(ur => ur.UserId == worker.WorkerId); _userRoleDal.Delete(oldRole); _userRoleDal.Add(userRole); return(new SuccessResult()); } catch (Exception) { return(new ErrorResult(Messages.ErrorWhileAddingEntity)); } }
public async Task <UserForListDto> Update(UserForRegisterDto userForRegisterDto) { var userFromRepo = await userDal.GetAsync(x => x.Email == userForRegisterDto.Email); if (userFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { UserNotFound = Messages.UserNotFound }); } var userForUpdate = mapper.Map(userForRegisterDto, userFromRepo); var userUpdate = await userDal.Update(userForUpdate); var spec = new UserWithCampusAndDepartmentAndDegreeSpecification(userUpdate.Email); var user = await userDal.GetEntityWithSpecAsync(spec); var chekcPublicRoles = await announceStatusCheck.CheckPublicRole(roleDal, roleCategoryDal); var userRolePublic = await userRoleDal.GetAsync(x => x.Role.Name.ToLower() == "public"); if (user.IsActive) { if (userRolePublic == null) { userRolePublic = new UserRole { UserId = user.Id, RoleId = chekcPublicRoles.Id }; await userRoleDal.Add(userRolePublic); } } else if (!user.IsActive) { if (userRolePublic != null) { await userRoleDal.Delete(userRolePublic); } } return(mapper.Map <User, UserForListDto>(user)); }
public IDataResult <User> Register(UserForRegisterDto userForRegisterDto, string password) { if (UserExists(userForRegisterDto.Email)) { return(new ErrorDataResult <User>(Messages.UserAlreadyExists)); } byte[] passwordSalt, passwordHash; HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); var user = new User { FirstName = userForRegisterDto.FirstName, LastName = userForRegisterDto.LastName, Email = userForRegisterDto.Email, GenderId = userForRegisterDto.GenderId, PhoneNumber = userForRegisterDto.PhoneNumber, PasswordHash = passwordHash, PasswordSalt = passwordSalt }; try { _userDal.Add(user); _userRoleDal.Add(new UserRole { RoleId = 1, //customer UserId = _userService.GetByMail(user.Email).Data.Id }); return(new SuccessDataResult <User>(user)); } catch (Exception e) { return(new ErrorDataResult <User>(Messages.ErrorWhileAddingEntity)); } }
public UserRole Add(UserRole userRole) { return(_userRoleDal.Add(userRole)); }
public UserRole Add(UserRole entity) { return(_userRoleDal.Add(entity)); }
//[FluentValidationAspect(typeof(Microsoft.VisualStudio.TextTemplating28D969267979CD858E05D2BE5C0F6ADD2B952A5E4B5839D76153D9D05D4F46628B4E7B0E544A47E640C6C022B4FE46EE0D2694C76AACC0B5253C56B7E99D54CF.GeneratedTextTransformation+DatabaseTableValidatior))] //[CacheRemoAspect(typeof(MemoryCacheManager))] public UserRole Add(UserRole userrole) { //ValidatorTool.FluentValidate( new Microsoft.VisualStudio.TextTemplating28D969267979CD858E05D2BE5C0F6ADD2B952A5E4B5839D76153D9D05D4F46628B4E7B0E544A47E640C6C022B4FE46EE0D2694C76AACC0B5253C56B7E99D54CF.GeneratedTextTransformation+DatabaseTableValidatior(), UserRole); return(_userroleDal.Add(userrole)); }