コード例 #1
0
        public ActionResult AddComment(UserAds model)
        {
            model.comm.DateTime = DateTime.Now;
            var query1 = new Neo4jClient.Cypher.CypherQuery("match(u{Email:'" + model.comm.Object.Email + "'}), (m{Email:'" + model.comm.Subject.Email + "'}) create (m)-[c:COMMENT{Content:'" + model.comm.Content + "', DateTime:'" + model.comm.DateTime + "'}]->(u) ", new Dictionary <string, object>(), CypherResultMode.Set);

            ((IRawGraphClient)client).ExecuteCypher(query1);
            return(RedirectToAction("UserProfile", new { email = model.comm.Object.Email }));
        }
コード例 #2
0
        public AdsBag SaleAd(AdsBag adDados)
        {
            using (var db = DatabaseFactory.OpenDbConnection())
            {
                using (var trans = db.OpenTransaction(System.Data.IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        if (db.Exists <UserInfoPayment>(NimbusUser.UserId))
                        {
                            Ad ad = new Ad
                            {
                                CategoryId = adDados.CategoryId,
                                ChannelId  = adDados.ChannelId,
                                ImgUrl     = adDados.ImgUrl,
                                TypeAd     = adDados.TypeAd,
                                Url        = adDados.Url,
                                Visible    = false
                            };
                            db.Insert(ad);

                            int    idAds   = (int)db.GetLastInsertId();
                            double priceAd = db.SelectParam <Prices>(p => p.Id == adDados.PriceId).Select(p => p.Price).FirstOrDefault();

                            UserAds userAd = new UserAds();
                            userAd.AdsId      = idAds;
                            userAd.CountClick = 0;
                            userAd.CountDay   = 0;
                            //quantidade de cliques ou dias restantes
                            userAd.CountLeft   = (int)((adDados.Credits) / priceAd);
                            userAd.Credits     = adDados.Credits;
                            userAd.DatePayment = null;
                            userAd.IsPaid      = false;
                            userAd.UserId      = NimbusUser.UserId;

                            db.Save(userAd);
                            trans.Commit();
                        }
                        else
                        {
                            throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "registro incompleto"));
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
                    }
                }
            }

            return(adDados);
        }
コード例 #3
0
        public ActionResult UserProfile(string email)
        {
            var       qu        = new Neo4jClient.Cypher.CypherQuery("match (u{Email:'" + User.Identity.Name + "'})-[f:FOLLOW]->(m{Email:'" + email + "'}) return true", new Dictionary <string, object>(), CypherResultMode.Set);
            bool      b         = ((IRawGraphClient)client).ExecuteGetCypherResults <bool>(qu).FirstOrDefault();
            List <Ad> ads       = new List <Ad>();
            var       query     = new Neo4jClient.Cypher.CypherQuery("match(u:User) where u.Email='" + email + "'	 return u", new Dictionary <string, object>(), CypherResultMode.Set);
            User      us        = ((IRawGraphClient)client).ExecuteGetCypherResults <User>(query).FirstOrDefault();
            var       queryy    = new Neo4jClient.Cypher.CypherQuery("match(u:User) where u.Email='" + User.Identity.Name + "' return u", new Dictionary <string, object>(), CypherResultMode.Set);
            User      usSubject = ((IRawGraphClient)client).ExecuteGetCypherResults <User>(queryy).FirstOrDefault();

            if (b)
            {
                us.SecurityStamp = "1";
            }
            var           qq       = new Neo4jClient.Cypher.CypherQuery("match (u:User)-[o:OFFER]->(m{Email:'" + User.Identity.Name + "'}) return count(o)", new Dictionary <string, object>(), CypherResultMode.Set);
            int           offernum = ((IRawGraphClient)client).ExecuteGetCypherResults <int>(qq).FirstOrDefault();
            var           query1   = new Neo4jClient.Cypher.CypherQuery("match(u{ Email:'" + email + "'})-[SELLING]->(r:Record)   return r", new Dictionary <string, object>(), CypherResultMode.Set);
            List <Record> records  = ((IRawGraphClient)client).ExecuteGetCypherResults <Record>(query1).ToList();

            foreach (Record rec in records)
            {
                var q = client.Cypher.Match("(r:Record {Id:'" + rec.Id + "'})<-[RELEASE]-(l:Label),(r:Record {Id:'" + rec.Id + "'})<-[OWNS]-(a:Artist),(r:Record {Id:'" + rec.Id + "'})<-[s:SELLING]-(u:User)  ").Return((l, a, u, s) => new { Label = l.As <Label>(), Artist = a.As <Artist>(), User = u.As <User>(), Condition = s.As <Condition>() });;
                foreach (var result in q.Results)
                {
                    ads.Add(new Ad {
                        Artist = result.Artist, Record = rec, Label = result.Label, User = result.User, Songs = getAllRecordSongs(rec.Id), Condition = result.Condition
                    });
                }
            }
            var            q1             = new Neo4jClient.Cypher.CypherQuery("match(u{Email:'" + email + "'})-[f:FOLLOW]->() return count(f)", new Dictionary <string, object>(), CypherResultMode.Set);
            int            numOfFollowing = ((IRawGraphClient)client).ExecuteGetCypherResults <int>(q1).FirstOrDefault();
            var            q2             = new Neo4jClient.Cypher.CypherQuery("match(u{Email:'" + email + "'})<-[f:FOLLOW]-() return count(f)", new Dictionary <string, object>(), CypherResultMode.Set);
            int            numOfFollowers = ((IRawGraphClient)client).ExecuteGetCypherResults <int>(q2).FirstOrDefault();
            var            q3             = client.Cypher.Match("(u{Email:'" + email + "'})<-[c:COMMENT]-(m)").Return((u, c, m) => new { Object = u.As <User>(), Content = c.As <Comment>(), Subject = m.As <User>() });;
            List <Comment> tmp            = new List <Comment>();

            foreach (var item in q3.Results)
            {
                tmp.Add(new Comment {
                    Content = item.Content.Content, Object = item.Object, Subject = item.Subject, DateTime = item.Content.DateTime
                });
            }

            Comment comm = new Comment {
                Object = us, Subject = usSubject
            };
            UserAds userAds = new UserAds {
                Ads = ads, User = us, Followers = numOfFollowers, Following = numOfFollowing, OfferNum = offernum, FavGenre = getFavouriteGenre(email), comm = comm, Comments = tmp
            };

            return(View(userAds));
        }