Example #1
0
        public EditSubResponse Handle(EditSub command)
        {
            var response = new EditSubResponse();

            try
            {
                var sub = _subService.GetSubByName(command.Name);

                if (sub == null)
                {
                    response.Error = "No sub found with the given name.";
                    return(response);
                }

                var user = _membershipService.GetUserById(command.EditedByUserId);

                if (user == null)
                {
                    response.Error = "Invalid user.";
                    return(response);
                }

                if (!_subService.CanUserEditSub(user.UserName, sub.Name))
                {
                    response.Error = "You are not allowed to modify this sub.";
                    return(response);
                }

                if (string.IsNullOrEmpty(command.Description))
                {
                    response.Error = "Please describe your sub.";
                    return(response);
                }

                sub.Description = command.Description;
                sub.SidebarText = command.SidebarText;

                _subService.UpdateSub(sub);
            }
            catch (Exception ex)
            {
                // todo: log
                response.Error = ex.Message;
            }

            return(response);
        }