public void CreateGroup(GroupViewModel newGroup, int userId) { int groupId = _groupRepository.Add(newGroup.ToEntity()); var role = _roleRepository.Get(r => r.Name.Equals(RoleNames.ROLE_OWNER)).Single(); GroupMember groupMember = new GroupMember() { GroupId = groupId, UserId = userId, RoleId = role.Id, JoinedAt = DateTime.Now }; _groupMemberRepository.AddUserToGroup(groupMember); }
public async Task <AuthorizationResponseModel> RegisterAsync(AuthorizationRequestModel registrationModel) { RoleData role = applicationRoleRepository.Get(registrationModel.Role); RegistrationResponseModel response = new RegistrationResponseModel() { IsSuccessful = false, Message = string.Empty }; var userData = new UserData { Email = registrationModel.Email, Password = registrationModel.Password, RoleId = role.Id }; IdentityResult userCreatingResult = await applicationUserRepository.CreateAsync(userData); if (!userCreatingResult.Succeeded) { // pushing message of first error in array response.Message = GetErrorMessage(userCreatingResult); return(response); } userData = await applicationUserRepository.FindByEmailAsync(userData.Email); ClientData client = new ClientData() { Name = registrationModel.UserName, Surname = registrationModel.Surname, PhotoPath = "default/profile.png", UserId = userData.Id }; ClientData addedClient = await clientRepository.AddAsync(client); if (addedClient == null) { response.Message = "Client not added"; } response.IsSuccessful = true; string token = javascriptWebTokenFactory.Create(userData.Id); var sessionData = new SessionData { UserId = userData.Id, Token = token, }; await sessionRepository.CreateAsync(sessionData); response.Token = token; return(response); }