Exemplo n.º 1
0
        public async Task <List <DepartmentService> > Get()
        {
            List <DepartmentService> services = await _dbContext.DepartmentServices.ToListAsync();

            if (services.Count() == 0)
            {
                DepartmentService ds1 = new DepartmentService()
                {
                    Id = 0, EnglishLabel = "Cat Petting Service", FrenchLabel = "Cat Petting Service - FR"
                };
                DepartmentService ds2 = new DepartmentService()
                {
                    Id = 1, EnglishLabel = "Dog Sitting Service", FrenchLabel = "Dog Sitting Serbvice - FR"
                };

                _dbContext.Add(ds1);
                _dbContext.Add(ds2);
                _dbContext.SaveChanges();

                services.Add(ds1);
                services.Add(ds2);
            }

            return(services);
        }
        public IActionResult Put(SubmitReviewModel model)
        {
            int serviceId = model.ServiceId;
            int ratingId  = model.RatingId;

            string userId = _userManager.GetUserId(User);

            var serviceObject = _dbContext.DepartmentServices.FirstOrDefault(x => x.Id == serviceId);
            var rating        = _dbContext.Ratings.FirstOrDefault(x => x.Id == ratingId);
            var userData      = _dbContext.Users.FirstOrDefault(x => x.Id == userId);


            Review userReview = new Review {
                User = userData,
                DepartmentService = serviceObject,
                Rating            = rating,
                Comment           = model.Comment
            };

            _dbContext.Add(userReview);
            _dbContext.SaveChanges();

            return(Ok(userReview));
        }