public async Task <Group> RegisterAsync(String name, UserSession loggedUserSession) { Group group = new Group(); group.Name = name; group.OwnerUserId = loggedUserSession.UserId; group.Members = new List <string>() { loggedUserSession.UserId }; if (!StringUtils.hasText(group.Name)) { throw new ValidationException("Name is required"); } await groupRepository.InsertAsync(group); // register the topic! Destination destinationGroup = new Destination(DestinationType.Group, group.Id); await messageSender.RegisterDestinationAsync(destinationGroup); // register the owner as member await messageSender.RegisterDestinationListenerAsync( new Destination(DestinationType.Group, group.Id), new Destination(DestinationType.User, loggedUserSession.UserId)); return(group); }
public async Task RegisterAsync(UserProfile user) { if (!StringUtils.hasText(user.Username)) { throw new ValidationException("username is required"); } if (!StringUtils.hasText(user.Password)) { throw new ValidationException("password is required"); } if (user.BirthDate == null || user.BirthDate == DateTime.MinValue) { throw new ValidationException("BirthDate is required"); } var dbUser = await userRepository.FindByUsernameAsync(user.Username); if (dbUser != null) { throw new ValidationException("username already exists"); } user.Password = (PasswordUtil.encode(user.Password)); await userRepository.InsertAsync(user); try { await messageSender.RegisterDestinationAsync(new Destination(DestinationType.User, user.Id)); } catch (Exception e) { await userRepository.DeleteByIdAsync(user.Id); throw; } }