예제 #1
0
        public IHttpActionResult Post(DriverRatingCreate rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateDriverRatingService();

            if (!service.CreateDriverRating(rating))
            {
                return(InternalServerError());
            }

            return(Ok("The driver rating was successfully created."));
        }
예제 #2
0
        public bool CreateDriverRating(DriverRatingCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =

                    new DriverRating()
                {
                    ApplicationUser         = _userId,
                    DriverId                = model.DriverId,
                    DriverFunScore          = model.DriverFunScore,
                    DriverSafetyScore       = model.DriverSafetyScore,
                    DriverCleanlinessScore  = model.DriverCleanlinessScore,
                    UserCreatedDriverRating = ctx.Users.Single(dr => dr.Id == _userId.ToString()).UserName,
                };

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