public CreateSubResponse Handle(CreateSub command) { var response = new CreateSubResponse(); try { if (string.IsNullOrEmpty(command.Name)) { response.Error = "Sub name is required."; return(response); } if (!Regex.IsMatch(command.Name, "^[a-zA-Z0-9]*$")) { response.Error = "No spaces or special characters."; return(response); } if (command.Name.Length > 20) { response.Error = "The name length is limited to 20 characters."; return(response); } if (string.IsNullOrEmpty(command.Description)) { response.Error = "Please describe your sub."; return(response); } var user = _membershipService.GetUserById(command.CreatedByUserId); if (user == null) { response.Error = "Invalid user."; return(response); } var sub = new Sub { Id = GuidUtil.NewSequentialId(), Name = command.Name, Description = command.Description, SidebarText = command.SidebarText }; _subService.InsertSub(sub); response.SubId = sub.Id; response.SubName = sub.Name; _subService.SubscribeToSub(user.UserName, sub.Name); _subService.AddAdminToSub(user.UserName, sub.Name); } catch (Exception ex) { // todo: log response.Error = ex.Message; } return(response); }