public override ApiResponse ApiProviderViewPost(IRequest request)
        {
            var parentNodeId = new NodeIdentifier(
                   WebUtility.UrlDecode(request.PostArgs["parent_provider"]),
                   WebUtility.UrlDecode(request.PostArgs["parent_id"]));
            var parentNode = request.UnitOfWork.Nodes.FindById(parentNodeId);
            if (parentNode == null)
                return new BadRequestApiResponse();

            if (parentNode.User.Id != request.UserId)
                return new ForbiddenApiResponse();

            var results = new List<NodeWithRenderedLink>();
            if (string.IsNullOrEmpty(request.PostArgs["text"]))
                return new BadRequestApiResponse("Text is not specified");

            var newNode = new TextNode
            {
                DateAdded = DateTime.Now,
                Text = request.PostArgs["text"],
                User = request.User
            };

            request.UnitOfWork.Text.Save(newNode);
            results.Add(new NodeWithRenderedLink(newNode,
                Utilities.CreateLinkForNode(request, parentNode, newNode)));

            return new ApiResponse(results, 201, "Nodes added");
        }
Beispiel #2
0
        private static int AddUser(CreateUserOptions options)
        {
            using (var unit = new UnitOfWork())
            {
                var password = unit.Users.CreateNewPasswordString(options.Password);
                var user = new User
                {
                    DateJoined = DateTime.Now,
                    Email = options.Email,
                    Password = password,
                    Username = options.Username
                };
                unit.Users.Save(user);
                var node = new TextNode
                {
                    DateAdded = DateTime.Now,
                    Text = "Home",
                    User = user
                };
                unit.Text.Save(node);
                user.Home = node;
                unit.Users.Save(user);
            }

            return 0;
        }
 public TextNodeDrop(TextNode node)
     : base(node)
 {
     _node = node;
 }