public async Task <IActionResult> UnSubscriberLearningPlanAsync([FromBody] LearningPlanFeedBack learningPlanFeedback) { GiveStarPayload LearningPlanSubscriber = new GiveStarPayload { Subscribe = learningPlanFeedback.Subscribe }; await client.client.Cypher .Match("(user:User)", "(lp:LearningPlan)") .Where((User user) => user.UserId == learningPlanFeedback.UserId) .AndWhere((LearningPlan lp) => lp.LearningPlanId == learningPlanFeedback.LearningPlanId) .Merge("(user)-[g:Subscribe_LP]->(lp)") .Delete("g") .ExecuteWithoutResultsAsync(); var totalsubscriber = await client.client.Cypher .Match("(:User)-[g:Subscribe_LP]->(lp:LearningPlan {LearningPlanId:{id}})") // .Match((GiveStarPayload sub)=>sub.Subscribe==1) .With("lp, count(g.Subscribe) as total_subscriber ") .Set("lp.Subscriber = total_subscriber") .WithParams(new { id = learningPlanFeedback.LearningPlanId, // rating= }) .Return <int>("lp.Subscriber") // .Return (g => Avg(g.As<GiveStarPayload>().Rating)) .ResultsAsync; return(Ok(new List <int>(totalsubscriber)[0])); }
public async Task <IActionResult> RatingLearningPlanAsync([FromBody] LearningPlanFeedBack learningPlanFeedback) { GiveStarPayload giveStar = new GiveStarPayload { Rating = learningPlanFeedback.Star }; await client.client.Cypher .Match("(user:User)", "(lp:LearningPlan)") .Where((User user) => user.UserId == learningPlanFeedback.UserId) .AndWhere((LearningPlan lp) => lp.LearningPlanId == learningPlanFeedback.LearningPlanId) .Merge("(user)-[g:RATING_LP]->(lp)") .OnCreate() .Set("g={giveStar}") .OnMatch() .Set("g={giveStar}") .WithParams(new { userRating = learningPlanFeedback.Star, giveStar }) .ExecuteWithoutResultsAsync(); var LPqueryAvg = await client.client.Cypher .Match("(:User)-[g:RATING_LP]->(lp:LearningPlan {LearningPlanId:{id}})") .With("lp, avg(g.Rating) as avg_rating ") .Set("lp.AvgRating = avg_rating") .WithParams(new { id = learningPlanFeedback.LearningPlanId, // rating= }) .Return <float>("lp.AvgRating") .ResultsAsync; // .Return (g => Avg(g.As<GiveStarPayload>().Rating)) return(Ok(new List <float>(LPqueryAvg)[0])); }