示例#1
0
        public bool Review(Review review)
        {
            if (review == null || review.UserID == 0 || review.BeerID == 0)
            {
                throw new ArgumentNullException("review");
            }

            using (var context = new BeerBoutiqueEntities())
            {
                var rev = context.Reviews.FirstOrDefault(x => x.BeerID == review.BeerID && x.UserID == review.UserID);

                if (rev == null)
                {
                    context.Reviews.Add(review);
                }
                else
                {
                    rev.AppearanceScore = review.AppearanceScore;
                    rev.AppearanceDescription = review.AppearanceDescription;
                    rev.AromaScore = review.AromaScore;
                    rev.AromaDescription = review.AromaDescription;
                    rev.TasteScore = review.TasteScore;
                    rev.TasteDescription = review.TasteDescription;
                    rev.OverallDescription = review.OverallDescription;
                }

                context.SaveChanges();
                return true;
            }
        }
示例#2
0
        public ActionResult _Review(Review review)
        {
            if (ModelState.IsValid) {
                var reviewFacade = new ReviewFacade();

                review.UserID = WebSecurity.CurrentUserId;
                reviewFacade.Review(review);

                return View();
            }
            else {
                throw new Exception("Invalid Model State");
            }
        }
示例#3
0
        static void Main()
        {
            var shards = new Dictionary<string, IDocumentStore>
            {
                { "Asia", new DocumentStore { Url = "http://localhost:8083"} },
                { "Middle East", new DocumentStore { Url = "http://localhost:8081"} },
                { "America", new DocumentStore { Url = "http://localhost:8082"} },
            };

            var shardStrategy = new ShardStrategy(shards)
                .ShardingOn<User>(user => user.Region)
                .ShardingOn<Review>(review => review.UserId)
                .ShardingOn<ReviewComments>(reviewComments => reviewComments.Review.Id);

            var documentStore = new ShardedDocumentStore(shardStrategy)
                .Initialize();

            var reviewId = string.Empty;

            using (var session = documentStore.OpenSession())
            {
                var batman = new User { UserName = "******", Region = "Asia" };
                var superman = new User { UserName = "******", Region = "Middle East" };
                var ironman = new User { UserName = "******", Region = "America" };

                session.Store(batman);
                session.Store(superman);
                session.Store(ironman);

                var badReview = new Review { UserId = batman.Id };
                var normalReview = new Review { UserId = superman.Id };
                var superReview = new Review { UserId = ironman.Id };

                session.Store(badReview);
                session.Store(normalReview);
                session.Store(superReview);

                var reviewComments = new ReviewComments();
                reviewComments.Comments.Add(new Comment { Message = "First comments" });
                reviewComments.Comments.Add(new Comment { Message = "Second comments" });
                reviewComments.Comments.Add(new Comment { Message = "Third comments" });
                reviewComments.Review.Id = superReview.Id;
                session.Store(reviewComments);

                superReview.CommentsId = reviewComments.Id;

                session.SaveChanges();

                reviewId = superReview.Id;
            }

            using (var session = documentStore.OpenSession())
            {
                var reviewOne = session.Include<Review, User>(x => x.UserId)
                    .Load(reviewId);

                var user = session.Load<User>(reviewOne.UserId);

                //var reviewTwo = session.Include<Review, ReviewComments>(x => x.CommentsId)
                //	.Load(reviewId);

                //var reviewComments = session.Load<ReviewComments>(reviewTwo.CommentsId);
            }
        }