public SubcribeToSubResponse Handle(SubcribeToSub command) { var response = new SubcribeToSubResponse(); try { var user = _membershipService.GetUserByUserName(command.UserName); if (user == null) { response.Error = "Invalid user."; return(response); } var sub = command.SubId.HasValue ? _subService.GetSubById(command.SubId.Value) : _subService.GetSubByName(command.SubName); if (sub == null) { response.Error = "Invalid sub name."; return(response); } // todo: check for private subs // todo: check if the user is subcribed to too many subs var subscribedSubs = _subService.GetSubscribedSubsForUser(user.Id); if (subscribedSubs.Contains(sub.Id)) { // already subscribed! response.Success = true; return(response); } if (subscribedSubs.Count >= _subSettings.Settings.MaximumNumberOfSubscribedSubs) { response.Error = "You cannot have more than " + _subSettings.Settings.MaximumNumberOfSubscribedSubs + " subscribed subs."; return(response); } _subService.SubscribeToSub(user.Id, sub.Id); _eventBus.Publish(new SubScriptionChanged { Subcribed = true, UserId = user.Id, SubId = sub.Id }); response.Success = true; } catch (Exception ex) { response.Error = ex.Message; return(response); } return(response); }