예제 #1
0
        public static List <TopicDetailsEOModel> GetAllDetailsForTopic(string topic)
        {
            int count = 0;
            List <SaveAllCR> saveAllCRList = new List <SaveAllCR>();
            //SaveAllCR saveAllCR = new SaveAllCR();

            //Relation relation = new Relation();
            //ConceptOne c1Details = new ConceptOne();
            //ConceptTwo c2Details = new ConceptTwo();
            //Topic topicDBEntity = new Topic();

            List <TopicDetailsEOModel> topicDetailsEOList = new List <TopicDetailsEOModel>();

            try
            {
                using (var context = new ConceptsRelationDBEntities())
                {
                    saveAllCRList = context.SaveAllCRs.Where(tp => tp.Topic.TopicsName == topic).ToList <SaveAllCR>();

                    foreach (SaveAllCR cr in saveAllCRList)
                    {
                        TopicDetailsEOModel tdEoModel = new TopicDetailsEOModel();
                        tdEoModel.TopicDetailsId = cr.Id;
                        tdEoModel.ConceptOne     = cr.ConceptOne.ConceptOneName;
                        tdEoModel.ConceptTwo     = cr.ConceptOne1.ConceptOneName;
                        tdEoModel.RelationType   = cr.Relation.RelationName;
                        tdEoModel.TopicName      = cr.Topic.TopicsName;

                        topicDetailsEOList.Add(tdEoModel);

                        //topicDetailsEOList.Add(new TopicDetailsEOModel
                        //{
                        //    TopicDetailsId = cr.Id,
                        //    ConceptOne = cr.ConceptOne.ConceptOneName,
                        //    //ConceptTwo = cr.ConceptTwo.ConceptTwoName,
                        //    ConceptTwo = cr.ConceptOne.ConceptOneName,
                        //    RelationType = cr.Relation.RelationName,
                        //    TopicName = cr.Topic.TopicsName
                        //});
                    }
                }

                return(topicDetailsEOList);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #2
0
        public static bool SaveAllDetails(string topic, int rtVal, int c1Val, int c2Val, bool isEdit, int editTopicId)
        {
            int                        count              = 0;
            Topic                      topicDBEntity      = new Topic();
            List <SaveAllCR>           saveAllCRList      = new List <SaveAllCR>();
            List <TopicDetailsEOModel> topicDetailsEOList = new List <TopicDetailsEOModel>();

            try
            {
                using (var context = new ConceptsRelationDBEntities())
                {
                    topicDBEntity = context.Topics.Where(tp => tp.TopicsName == topic).FirstOrDefault();

                    if (!isEdit && editTopicId == 0)
                    {
                        //Save new record
                        context.SaveAllCRs.Add(
                            new SaveAllCR
                        {
                            fTopicId = topicDBEntity.TopicID,
                            fRId     = rtVal,
                            fC1Id    = c1Val,
                            fC2Id    = c2Val
                        });
                    }
                    else
                    {
                        // Update Existing record
                        //var result = context.SaveAllCRs.SingleOrDefault(tp => tp.Topic.TopicsName == topic &&
                        //                                                    tp.fC1Id == c1Val &&
                        //                                                    tp.fC1Id == c2Val &&
                        //                                                    tp.fRId == rtVal
                        //                                                    );
                        var result = context.SaveAllCRs.SingleOrDefault(tp => tp.Id == editTopicId);
                        if (result != null)
                        {
                            result.fC1Id = c1Val;
                            result.fC2Id = c2Val;
                            result.fRId  = rtVal;
                        }
                    }
                    count = context.SaveChanges();
                }

                if (count > 0)
                {
                    using (var context = new ConceptsRelationDBEntities())
                    {
                        //Home1 hm1 = new Home1();
                        //hm1.grdvConceptRelation.DataSource = context.MasterConceptRelations.Where(c => c.TopicName == "Topic 2").ToList<MasterConceptRelation>();
                        //hm1.grdvConceptRelation.DataBind();
                    }



                    using (var context = new ConceptsRelationDBEntities())
                    {
                        saveAllCRList = context.SaveAllCRs.Where(tp => tp.Topic.TopicsName == topic && tp.Relation.RelID == rtVal && tp.ConceptOne.C1Id == c1Val && tp.ConceptTwo.C2Id == c2Val).ToList <SaveAllCR>();

                        foreach (SaveAllCR cr in saveAllCRList)
                        {
                            TopicDetailsEOModel tdEoModel = new TopicDetailsEOModel();
                            tdEoModel.TopicDetailsId = cr.Id;
                            tdEoModel.ConceptOne     = cr.ConceptOne.ConceptOneName;
                            tdEoModel.ConceptTwo     = cr.ConceptOne1.ConceptOneName;
                            tdEoModel.RelationType   = cr.Relation.RelationName;
                            tdEoModel.TopicName      = cr.Topic.TopicsName;

                            topicDetailsEOList.Add(tdEoModel);

                            //topicDetailsEOList.Add(new TopicDetailsEOModel
                            //{
                            //    TopicDetailsId = cr.Id,
                            //    ConceptOne = cr.ConceptOne.ConceptOneName,
                            //    ConceptTwo = cr.ConceptTwo.ConceptTwoName,
                            //    RelationType = cr.Relation.RelationName,
                            //    TopicName = cr.Topic.TopicsName
                            //});
                        }
                    }

                    var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "ismail123")
                    {
                        JsonContractResolver = new CamelCasePropertyNamesContractResolver()
                    };

                    client.Connect();
                    List <string> con1list = topicDetailsEOList.Select(X => X.ConceptOne).Distinct().ToList();
                    string        concept1 = string.Join(",", con1list);
                    List <string> con2list = topicDetailsEOList.Select(X => X.ConceptTwo).Distinct().ToList();
                    string        concept2 = string.Join(",", con2list);
                    List <string> rellist  = topicDetailsEOList.Select(X => X.RelationType).Distinct().ToList();
                    string        relation = string.Join(",", rellist);
                    string        rel      = "(conceptone1)-[:" + relation + "]->(conceptone2)";

                    client.Cypher
                    .Match("(conceptone1:ConceptOne)", "(conceptone2:ConceptOne)")
                    .Where((ConceptOne1 conceptone1) => conceptone1.Name == concept1)
                    .AndWhere((ConceptOne1 conceptone2) => conceptone2.Name == concept2)
                    .Create(rel)
                    .ExecuteWithoutResultsAsync()
                    .Wait();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }