Exemple #1
0
        public ActionResult FlagDeletion(Guid id)
        {
            string message = "An error occurred. The node was not flagged";

            Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            BasicNodeModel toDelete = null;

            using (NeoDriver driver = new NeoDriver())
            {
                toDelete = driver.GetNode(id);
            }

            // If the node with the given id is not null,
            if (toDelete != null)
            {
                DatabaseRequest request = new DatabaseRequest
                {
                    Id             = Guid.NewGuid(),
                    RequestType    = DatabaseRequestType.Delete,
                    SubmissionDate = DateTime.Now,
                    NodeDataType   = toDelete.ContentType,
                    NodeData       = JsonConvert.SerializeObject(BasicNodeViewModel.FromModel(toDelete)),
                    Approved       = false,
                    ApprovalDate   = null,
                    Notes          = null,
                    Reviewed       = false,
                    ReviewedDate   = null,
                    Reviewer       = null,
                    ReviewerRefId  = null
                };

                // Add a deletion request,
                using (ApplicationDbContext context = ApplicationDbContext.Create())
                {
                    request.Submitter = context.Users.Single(u => u.UserName == User.Identity.Name);
                    context.Requests.Add(request);
                    context.SaveChanges();
                }

                message             = "Node flagged for deletion";
                Response.StatusCode = (int)HttpStatusCode.Accepted;
            }
            else
            {
                message             = "Could not find the specified node.";
                Response.StatusCode = (int)HttpStatusCode.NotFound;
            }

            return(Json(new { message = message }));
        }
Exemple #2
0
        // GET: Edit/Index/
        public ActionResult Index(string id)
        {
            ActionResult result = View("Error");

            if (!string.IsNullOrWhiteSpace(id))
            {
                // Try to parse the Guid string
                Guid parsedId;
                if (Guid.TryParse(id, out parsedId))
                {
                    // The string was parsed, find the node
                    // We have been given an id of a node to edit
                    ViewBag.Title = "Edit Node Data";
                    BasicNodeViewModel viewModel = null;
                    // Get the node to edit
                    using (NeoDriver driver = new NeoDriver())
                    {
                        BasicNodeModel model = driver.GetNodeAndRelationships(parsedId);
                        viewModel = BasicNodeViewModel.FromModel(model);
                    }
                    // Return a view
                    if (viewModel != null)
                    {
                        result = View(model: viewModel);
                    }
                }
                else
                {
                    Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                    Response.StatusDescription = $"Invalid id value: {id}";
                }
            }
            else
            {
                // We are creating a new node
                ViewBag.Title = "Create New Node";
                result        = View(model: new BasicNodeViewModel {
                    Id = Guid.NewGuid(), ContentType = 0
                });
            }
            return(result);
        }