Exemplo n.º 1
0
        public async Task Approve(long id)
        {
            using (var ctx = new CMMIContext())
            {
                var entity = await ctx.Reviews.FindAsync(id);

                if (entity == null)
                {
                    throw new NotFoundException("Review not found.");
                }

                entity.Approved = true;

                await ctx.SaveChangesAsync();

                await UpdateRestaurantReviewDetails(ctx, entity.Restaurant);
            }
        }
Exemplo n.º 2
0
        public async Task <RestaurantViewModel> Update(long id, RestaurantBindingModel restaurant)
        {
            using (var ctx = new CMMIContext())
            {
                var entity = await ctx.Restaurants.FindAsync(id);

                if (entity == null)
                {
                    throw new NotFoundException("Restaurant not found.");
                }

                entity.Name = restaurant.Name;
                entity.City = restaurant.City;

                await ctx.SaveChangesAsync();

                return(new RestaurantViewModel(entity));
            }
        }
Exemplo n.º 3
0
        public async Task <RestaurantViewModel> Create(RestaurantBindingModel restaurant)
        {
            using (var ctx = new CMMIContext())
            {
                var entity = ctx.Restaurants.Create();
                entity.Name = restaurant.Name;
                entity.City = restaurant.City;

                entity.UserGuid = CurrentUserGuid;

                entity.Rating      = 0;
                entity.ReviewCount = 0;
                entity.CreateDate  = DateTime.Now;
                ctx.Restaurants.Add(entity);
                await ctx.SaveChangesAsync();

                return(new RestaurantViewModel(entity));
            }
        }
Exemplo n.º 4
0
        public async Task <ReviewViewModel> Update(long id, ReviewBindingModel review)
        {
            using (var ctx = new CMMIContext())
            {
                var entity = await ctx.Reviews.FindAsync(id);

                if (entity == null)
                {
                    throw new NotFoundException("Review not found.");
                }

                entity.Rating  = review.Rating;
                entity.Comment = review.Comment;

                await ctx.SaveChangesAsync();

                await UpdateRestaurantReviewDetails(ctx, entity.Restaurant);

                return(new ReviewViewModel(entity));
            }
        }
Exemplo n.º 5
0
        public async Task <ReviewViewModel> Create(long restaurantId, ReviewBindingModel review)
        {
            using (var ctx = new CMMIContext())
            {
                var entity = ctx.Reviews.Create();

                entity.UserGuid = CurrentUserGuid;

                entity.RestaurantId = restaurantId;
                entity.Rating       = review.Rating;
                entity.Comment      = review.Comment;

                entity.CreateDate = DateTime.Now;

                ctx.Reviews.Add(entity);
                await ctx.SaveChangesAsync();

                await UpdateRestaurantReviewDetails(ctx, entity.Restaurant);

                return(new ReviewViewModel(entity));
            }
        }