예제 #1
0
        public void GetRatingsShouldReturnTypeDouble()
        {
            //arrange
            var rating1       = new RatingCreate();
            var ratingService = new RatingServices();

            rating1.StarRating = 3.3;
            rating1.MovieId    = 1;
            ratingService.Create(rating1);

            //act
            using (var ctx = new ApplicationDbContext())
            {
                var query =
                    ctx
                    .Ratings
                    .Select(
                        e =>
                        new RatingListItem
                {
                    RatingId   = e.RatingId,
                    StarRating = e.StarRating
                }
                        );
                return(query.ToArray());
            }
        }
        public async Task <ActionResult> Create(RatingCreate note)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.RestaurantId = await GetRestaurantAsync();

                ViewBag.CustomerId = await GetCustomerAsync();

                ViewBag.DriverId = await GetDeliveryDriverAsync();

                return(View(note));
            }

            var service = CreateRatingService();

            if (await service.CreateRatingAsync(note))
            {
                TempData["SaveResult"] = "Your Menu was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Menu could not be created.");
            ViewBag.RestaurantId = await GetRestaurantAsync();

            ViewBag.CustomerId = await GetCustomerAsync();

            ViewBag.DriverId = await GetDeliveryDriverAsync();


            return(View(note));
        }
예제 #3
0
        public bool CreateRating(RatingCreate model)
        {
            var newRating = new Rating
            {
                Comments             = model.Comments,
                CleanlinessRating    = model.CleanlinessRating,
                EnvironmentRating    = model.EnvironmentRating,
                ResponsivenessRating = model.ResponsivenessRating,
                LuxuryRating         = model.LuxuryRating,
                AccessibilityRating  = model.AccessibilityRating,
                RenterId             = model.RenterId,
                SpaceId = model.SpaceId
            };

            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Ratings.Add(newRating);

                    return(ctx.SaveChanges() == 1);
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(false);
            }
        }
        public ActionResult Create(RatingCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var service = CreateRaterService();

            if (service.CreateRating(model))
            {
                return(RedirectToAction("Index"));
            }

            var baseId      = Guid.Parse(User.Identity.GetUserId());
            var baseService = new BaseService(baseId);
            var baseList    = baseService.GetBasesByUserID(baseId);

            var raterId      = Guid.Parse(User.Identity.GetUserId());
            var raterService = new RaterService(raterId);
            var raterList    = raterService.GetRatersByUserID(raterId);


            ViewBag.BaseID  = new SelectList(baseList, "BaseID", "BaseName");
            ViewBag.RaterID = new SelectList(raterList, "RaterID", "DisplayInfo");


            return(View(model));
        }
예제 #5
0
        //Alright gents... here we go...

        //A few notes. First, we made was in the data assembly --> Ratings Class there were two classes inside of another class. We removed the class the was housing the two classes and commented out the one with the list in it.

        //Second, We also updated some names for clarification and added two Foreign Keys so that the ratings get connected to the specific instrument or product.

        //Third, I also changes the ID in accessory data table to "AccessoryId" for clarification

        //Fourth, we created an "AverageRating" property in both Instrument and Accessory data models


        //Directly below is the create a Product rating that takes in the values passed in through Postman and then calls in the AverageRating method (directly below) which creates the average and then saves it. Jess helped us so this a hybrid of the one he shared and the average method that was originally in here.

        //I'll note out steps
        public bool CreatingProductRating(RatingCreate model)
        {
            // Here is like all our other create functins just passing in the model
            var entity =
                new ProductRating()
            {
                StarRating   = model.StarRating,
                InstrumentId = model.InstrumentId,
                AccessoryId  = model.AccessoryId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                //Opened the Dbcontext and then "entity" passes in the model directly above
                ctx.Ratings.Add(entity);

                //This saves the changes the "entity" model passes into the Ratings Dbcontext before we send it to the AverageRating method. Jess wasn't sure why this step was needed, but I think it adds it to the table.
                ctx.SaveChanges();

                //This send the info to the averaging method below
                AverageRating(model.InstrumentId, model.AccessoryId);

                //It's odd everything actually runs through the Averaging method before it hits this step
                return(ctx.SaveChanges() == 0);
            }
        }
예제 #6
0
        public ActionResult CreateRating(int id, RatingCreate ratingModel)
        {
            var serviceRating  = new RatingService();
            var serviceMeaning = new MeaningService();
            var meaning        = serviceMeaning.GetMeaningById(id);

            serviceRating.CreateRating(id, ratingModel);

            return(RedirectToAction("DisplayComments", "Word", new { id = meaning.MeaningId }));
        }
예제 #7
0
        public ActionResult CreateRating(int id)
        {
            var service = new MeaningService();
            var model   = service.GetMeaningById(id);
            var rating  = new RatingCreate()
            {
                MeaningId = model.MeaningId,
            };

            return(View(rating));
        }
예제 #8
0
 public IHttpActionResult Post(RatingCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (_service.CreateRating(model))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
예제 #9
0
        public IHttpActionResult Post(RatingCreate rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateRatingService();

            if (!service.CreateRating(rating))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
예제 #10
0
        public bool Create(RatingCreate model)
        {
            var entity = new Rating()
            {
                StarRating = model.StarRating,
                MovieId    = (model.MovieId != null) ? model.MovieId : null,
                TVShowId   = (model.TVShowId != null) ? model.TVShowId : null
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #11
0
        public ActionResult Create(int wineId)
        {
            var wineSvc = CreateWineService();
            var wine    = wineSvc.GetWineById(wineId);

            var ratingSvc = CreateRatingService();

            var model = new RatingCreate
            {
                WineId         = wineId,
                CodeForTasting = wine.CodeForTasting
            };

            return(View(model));
        }
예제 #12
0
        public bool CreateRating(RatingCreate model)
        {
            var entity = new Rating()
            {
                AuthorId          = _userId,
                Rate              = model.Rate,
                ReviewDescription = model.ReviewDescription
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #13
0
        public bool CreateRatings(RatingCreate model)
        {
            var entity =
                new Ratings()
            {
                IsRecommended    = model.IsRecommended,
                IsFamilyFriendly = model.IsFamilyFriendly,
                ActualRating     = model.ActualRating
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #14
0
        public IHttpActionResult Post(RatingCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var _service = CreateRatingService();

            if (!_service.CreateRating(model))
            {
                return(InternalServerError());
            }

            return(Ok("Rating created successfully!"));
        }
예제 #15
0
        public bool CreateRating(RatingCreate model)
        {
            Rating rating = new Rating
            {
                UserId   = _userId,
                Score    = model.Score,
                EateryId = model.EateryId,
                RideId   = model.RideId,
                ShowId   = model.ShowId,
            };

            using (var e = new ApplicationDbContext())
            {
                e.Ratings.Add(rating);
                return(e.SaveChanges() == 1);
            }
        }
예제 #16
0
        public bool CreateRating(RatingCreate model)
        {
            var entity =
                new Ratings()
            {
                BoardId             = model.BoardId,
                AffordabilityRating = model.AffordabilityRating,
                DurablityRating     = model.DurablityRating,
                SpeedRating         = model.SpeedRating,
                Comment             = model.Comment
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #17
0
        public bool CreateRating(RatingCreate model)
        {
            var entity =
                new Rating()
            {
                CustomerId           = model.CustomerId,
                RestaurantId         = model.RestaurantId,
                RestaurantRating     = model.RestaurantRating,
                DeliveryDriverId     = model.DeliveryDriverId,
                DeliveryDriverRating = model.DeliveryDriverRating,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Rating.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #18
0
        public bool CreateRating(RatingCreate model)
        {
            var entity = new Rating()
            {
                OwnerId     = _userId,
                RatingId    = model.RatingId,
                WineId      = model.WineId,
                GuestRating = model.GuestRating,
                Comments    = model.Comments,
                CreatedUtc  = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #19
0
        public bool CreateRating(RatingCreate model)
        {
            var entity = new Rating()
            {
                CreatorId           = _creatorId,
                LocationId          = model.LocationId,
                CleanlinessRating   = model.CleanlinessRating,
                AccessibilityRating = model.AccessibilityRating,
                AmenitiesRating     = model.AmenitiesRating,
                CreatedUtc          = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #20
0
        // Post
        public bool CreateRating(RatingCreate model)
        {
            var entity =
                new SafetyRating()
            {
                HousingId = model.HousingId,
                //ApplicantId = model.ApplicantId,
                Rating = model.Rating,
                Posted = DateTime.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                entity.ApplicantUser = ctx.Users.Where(e => e.Id == _userId).First();
                ctx.SafetyRatings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #21
0
        public async Task <bool> CreateRatingAsync(RatingCreate model)
        {
            var entity =
                new Rating()
            {
                // OwnerID = _userId,
                CustomerId           = model.CustomerId,
                RestaurantId         = model.RestaurantId,
                RestaurantRating     = model.RestaurantRating,
                DeliveryDriverId     = model.DeliveryDriverId,
                DeliveryDriverRating = model.DeliveryDriverRating,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Rating.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
예제 #22
0
        public ActionResult Create(RatingCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateRatingService();

            if (service.CreateRating(model))
            {
                TempData["SaveResult"] = "Your rating was posted.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "rating could not be posted.");

            return(View(model));
        }
        public ActionResult Create(RatingCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateRatingService();

            if (service.CreateRating(model))
            {
                TempData["SaveResult"] = "The Safety Rating was succesfully created";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Your Safety Rating could not be added");

            //return View(model);
            return(RedirectToAction("Index"));
        }
예제 #24
0
        public bool CreateRating(int id, RatingCreate rating)
        {
            var serviceMeaning = new MeaningService();
            var meaning        = serviceMeaning.GetMeaningById(id);

            using (var ctx = new ApplicationDbContext())
            {
                var entity = new Rating()
                {
                    MeaningId        = meaning.MeaningId,
                    Comment          = rating.Comment,
                    IndividualRating = rating.IndividualRating,
                    RatingId         = rating.RatingId,
                };
                ctx.Ratings.Add(entity);
                //meaning.RatingsList.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateRating(RatingCreate model)
        {
            var rating = new BaseRating
            {
                OwnerID             = _userId,
                BaseID              = model.BaseID,
                RaterID             = model.RaterID,
                OverallRating       = model.OverallRating,
                HousingRating       = model.HousingRating,
                FoodRating          = model.FoodRating,
                ActivitiesRating    = model.ActivitiesRating,
                TrainingSitesRating = model.TrainingSitesRating,
                Comments            = model.Comments
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(rating);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #26
0
        public bool CreateRating(RatingCreate model)
        {
            var entity =
                new Rating()
            {
                EnjoymentScore   = model.EnjoymentScore,
                EngagementScore  = model.EngagementScore,
                AuthorStyleScore = model.AuthorStyleScore,
                Description      = model.Description,
                BookId           = model.BookId,
                UserId           = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);

                var bookEntity = ctx.Books.Find(model.BookId);
                bookEntity.RatingsForBook.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #27
0
        public bool CreateRating(RatingCreate model)
        {
            var entity =
                new Rating()
            {
                EnjoymentScore   = model.EnjoymentScore,
                SongLengthScore  = model.SongLengthScore,
                ArtistStyleScore = model.ArtistStyleScore,
                Description      = model.Description,
                SongId           = model.SongId,
                UserId           = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ratings.Add(entity);

                var songEntity = ctx.Songs.Find(model.SongId);
                songEntity.RatingsForSong.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #28
0
        public bool CreateRating(RatingCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var item = ctx.Features.Where(e => e.UserID == _userId && e.FeatureID == model.FeatureID && e.PropertyID == model.PropertyID).Select(e => new AllDetailsListItem
                {
                    PropertyID           = e.PropertyID,
                    FeatureID            = e.FeatureID,
                    DistanceFromPopulace = e.DistanceFromPopulace,
                    RoadAccess           = e.RoadAccess,
                    CityWater            = e.CityWater,
                    CityElectric         = e.CityElectric,
                    CitySewer            = e.CitySewer,
                    Internet             = e.Internet,
                    AlternateWater       = e.AlternateWater,
                    AlternateElectric    = e.AlternateElectric,
                    AlternateSewage      = e.AlternateSewage,
                    BodyOfWater          = e.BodyOfWater,
                    NearbyBodyOfWater    = e.NearbyBodyOfWater,
                    Price = e.Property.Price
                }).Single();

                decimal placeholder = 0;
                if (item.DistanceFromPopulace >= 25)
                {
                    placeholder += 10;
                }
                if (item.DistanceFromPopulace < 25)
                {
                    placeholder -= 4;
                }
                if (item.RoadAccess is true)
                {
                    placeholder += 10;
                }
                if (item.CityWater is true)
                {
                    placeholder += 8;
                }
                if (item.CityElectric is true)
                {
                    placeholder += 8;
                }
                if (item.CitySewer is true)
                {
                    placeholder += 8;
                }
                if (item.Internet is true)
                {
                    placeholder += 8;
                }
                if (item.AlternateWater is true)
                {
                    placeholder += 4;
                }
                if (item.AlternateElectric is true)
                {
                    placeholder += 4;
                }
                if (item.AlternateSewage is true)
                {
                    placeholder += 4;
                }
                if (item.BodyOfWater is true)
                {
                    placeholder += 4;
                }
                if (item.NearbyBodyOfWater is true)
                {
                    placeholder += 2;
                }

                if (item.Price <= 100000)
                {
                    placeholder += 30;
                }
                else if (item.Price > 100000 && item.Price <= 150000)
                {
                    placeholder += 15;
                }
                else if (item.Price > 150000 && item.Price <= 200000)
                {
                    placeholder += 5;
                }
                else if (item.Price >= 2500000)
                {
                    placeholder -= 30;
                }

                var entity = new RatingScore()
                {
                    UserID     = _userId,
                    PropertyID = model.PropertyID,
                    FeatureID  = model.FeatureID,
                    Rating     = placeholder / 10
                };

                ctx.Ratings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }