public Task SaveCafeReview(Review review)
        {
            var reviewTable = this.serviceClient.GetTable<Review>();
            
            if (review.Id == null)
            {
                review.Id = Guid.NewGuid().ToString();
                return reviewTable.InsertAsync(review);
            }

            return reviewTable.UpdateAsync(review);
        }
        public async Task SaveCafeReview(Review review)
        {
            var cafe = this.Cafes.Single(c => c.Id == review.CafeId);

            if (!this.Reviews.ContainsKey(cafe))
            {
                this.Reviews.Add(cafe, new List<Review>());
            }
            else
            {
                var existingReview = this.Reviews[cafe].FirstOrDefault(r => r.Id == review.Id);
                if (existingReview != null)
                {
                    this.Reviews[cafe].Remove(existingReview);
                }
            }

            this.Reviews[cafe].Add(review);
            
            cafe.NumberOfVotes = this.Reviews[cafe].Count(r => r.CoffeeRating.HasValue || r.AtmosphereRating.HasValue);
            cafe.CoffeeRating = this.Reviews[cafe].Average(r => r.CoffeeRating.HasValue ? r.CoffeeRating.Value : 0);
            cafe.AtmosphereRating = this.Reviews[cafe].Average(r => r.AtmosphereRating.HasValue ? r.AtmosphereRating.Value : 0);
        }
 private ReviewViewModel CreateReviewViewModel(Review model)
 {
     var viewModel = new ReviewViewModel(this.dataService, this.identityService);
     viewModel.Initialize(model);
     return viewModel;
 }
 public void Initialize(Review review = null)
 {
     this.Set(ref this.comment, review != null ? review.Comment : null);
     this.Set(ref this.coffeeRating, review != null ? review.CoffeeRating : null);
     this.Set(ref this.atmosphereRating, review != null ? review.AtmosphereRating : null);
     this.reviewId = review != null ? review.Id : null;
     this.SubmittedBy = review != null ? review.SubmittedBy : null;
     this.SubmittedDate = review != null ? review.SubmittedDate : (DateTime?) null;
     this.isDirty = false;
     this.Submit.RaiseCanExecuteChanged();
 }
 public ReviewSubmittedEventArgs(Review review)
 {
     this.Review = review;
 }
        private async void OnSubmitExecuted()
        {
            if (!this.identityService.IsAuthenticated)
            {
                if (!await this.identityService.AuthenticateAsync())
                {
                    return;
                }
            }

            if (!this.CanExecuteSubmit())
            {
                return;
            }

            if (this.comment != null)
            {
                var formatted = this.comment.Trim();
                formatted = formatted.Length > 0 ? formatted : null;
                this.comment = formatted;
                this.RaisePropertyChanged(() => this.Comment);
            }

            var review = new Review
                {
                    Id = this.reviewId,
                    CafeId = this.associatedCafe.Id,
                    Comment = this.comment,
                    SubmittedBy = this.identityService.CurrentUserId
                };
            if (this.coffeeRating.HasValue)
            {
                review.CoffeeRating = this.coffeeRating.Value;
            }
            if (this.atmosphereRating.HasValue)
            {
                review.AtmosphereRating = this.atmosphereRating.Value;
            }

            this.isDirty = false;
            this.Submit.RaiseCanExecuteChanged();

            if (review.Comment == null && review.CoffeeRating == null && review.AtmosphereRating == null)
            {
                return;
            }

            await this.dataService.SaveCafeReview(review);

            this.reviewId = review.Id;
            this.SubmittedBy = review.SubmittedBy;
            this.SubmittedDate = review.SubmittedDate;

            if (this.ReviewSubmitted != null)
            {
                this.ReviewSubmitted(this, new ReviewSubmittedEventArgs(review));
            }
        }
 public async Task SaveCafeReview(Review review)
 {
     var cafe = AllCafes.First(c => c.Id == review.CafeId);
     var reviews = CafeReviews[cafe].Where(rev => rev.SubmittedBy != review.SubmittedBy).ToList();
     reviews.Insert(0, review);
     CafeReviews[cafe] = reviews;
 }