public async Task <LearningPlanWrapper> CreateLearningPlanAndRelationshipsAsync(LearningPlanWrapper learningPlan) { try { var resources = new List <ResourceWrapper> (learningPlan.Resources); var technology = new TechnologyWrapper { Name = learningPlan.Technology.Name }; var authorId = learningPlan.AuthorId; learningPlan.AuthorId = null; learningPlan.Resources = null; learningPlan.Technology = null; var queryResult = await graph.Cypher .Merge("(lp:LearningPlan {LearningPlanId:\"" + learningPlan.LearningPlanId + "\"})") .OnCreate() .Set("lp = {learningPlan}") .With("lp") .Merge("(u:User{UserId:\"" + authorId + "\"})") .OnCreate() .Set("u={UserId:\"" + authorId + "\"}") .Merge("(u)-[:DESIGNS]->(lp)") .With("lp") .Merge("(t:Technology {Name:\"" + technology.Name + "\"})") .OnCreate() .Set("t={technology}") .Merge("(lp)-[:TEACHES]->(t)") .WithParams(new { technology, learningPlan }) .Return(lp => lp.As <LearningPlanWrapper> ()) .ResultsAsync; var lpResult = new List <LearningPlanWrapper> ( queryResult ) [0]; lpResult.Technology = technology; var resourceQuery = graph.Cypher .Match( "(lp:LearningPlan {LearningPlanId:\"" + learningPlan.LearningPlanId + "\"} )" ); lpResult.Resources = new List <ResourceWrapper> (); foreach (ResourceWrapper r in resources) { lpResult.Resources.Add(await AddResourceAsync(r)); resourceQuery = resourceQuery .With("lp") .Match( "(r:Resource {ResourceId:\"" + r.ResourceId + "\"})" ) .Merge("(lp)-[:CONTAINS]->(r)"); } Console.WriteLine("----------------LP->RESOURCE----------------------------"); Console.WriteLine(resourceQuery.Query.QueryText); await resourceQuery.ExecuteWithoutResultsAsync(); return(lpResult); } catch (Exception e) { Console.WriteLine("----------------------EXCEPTION-MESSAGE------------------------------------"); Console.WriteLine(e.Message); Console.WriteLine("----------------------STACK-TRACE-----------------------------------------"); Console.WriteLine(e.StackTrace); Console.WriteLine("-------------------------INNER-EXCEPTION-----------------------------"); Console.WriteLine(e.InnerException); return(null); } // return null; }
public async Task <IActionResult> PostAsync([FromBody] LearningPlanWrapper lp) { await Task.Yield(); return(Forbid()); }