public ActionResult UpdateRestaurantRating(int ratingId, [FromBody] RestaurantRating restaurantRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Please provide proper input"));
            }
            try
            {
                bool isRatingUpdated = _ratingBusiness.UpdateRestaurantRating(ratingId, restaurantRating);

                if (isRatingUpdated)
                {
                    return(AcceptedAtRoute("GetId", new { restaurantID = restaurantRating.RestaurantId }));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Entity Error") || (ex.Message.Contains("HttpPost method")))
                {
                    return(BadRequest(ex.Message));
                }

                return(StatusCode((int)HttpStatusCode.InternalServerError,
                                  $"Error in updating restaurant! Try again after some time."));
            }
        }
        public void UpdateRestaurantRating_WrongInput_RatingIDDoesntExist()
        {
            //Arrange
            int ratingId = 1000;
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                RatingId      = 1000,
                rating        = "9",
                user_Comments = "Good place to eat"
            };
            Exception exception          = new Exception("Rating doesn't exist for the Restaurant 1000! Try creating the same rating using HttpPost method.");
            var       mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.UpdateRestaurantRating(ratingId, restauratRatings)).Throws(exception);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.UpdateRestaurantRating(ratingId, restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(400, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, exception.Message);
        }
 public void Post(RestaurantRating restaurantRating)
 {
     if (restaurantRating.Id == 0)
         _restaurantRatingTask.AddRestaurantRating(restaurantRating);
     else
         _restaurantRatingTask.UpdateRestaurantRating(restaurantRating);
 }
Beispiel #4
0
        public void SubmitReview()
        {
            //Arrange
            RestaurantRating restaurantRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                customerId    = 1,
                rating        = 8,
                user_Comments = "Excellent",
            };
            var mockOrder  = new Mock <IReviewBusiness>();
            var mockOrder1 = new Mock <ILogService>();

            mockOrder.Setup(x => x.RestaurantRating(It.IsAny <RestaurantRating>()));
            mockOrder1.Setup(x => x.LogMessage("Submitted Reviews TestCase"));
            //Act
            var reviewcontroller = new ReviewController(mockOrder.Object, mockOrder1.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            var data           = reviewcontroller.ResturantRating(restaurantRatings);
            var okObjectResult = data as OkObjectResult;

            //Assert
            Assert.AreEqual(200, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
        }
        public ActionResult AddRestaurantRating([FromBody] RestaurantRating restaurantRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Please provide proper input"));
            }

            try
            {
                bool isRatingAdded = _ratingBusiness.AddRestaurantRating(restaurantRating, out RestaurantRating returnedRestaurantRating);

                if (isRatingAdded)
                {
                    return(CreatedAtRoute("GetId", new { restaurantID = returnedRestaurantRating.RestaurantId }, returnedRestaurantRating));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Entity Error") || ex.Message.Contains("Restaurant doesn't exist"))
                {
                    return(BadRequest(ex.Message));
                }

                return(StatusCode((int)HttpStatusCode.InternalServerError,
                                  $"Error in creating restaurant! Try again after some time."));
            }
        }
Beispiel #6
0
        public bool UpdateRestaurantRating(int ratingId, RestaurantRating restaurantRating)
        {
            try
            {
                if (!DoesRatingForRestaurantExists(restaurantRating.RestaurantId, ratingId))
                {
                    throw new Exception($"Rating doesn't exist for the Restaurant {restaurantRating.RestaurantId}! " +
                                        $"Try creating the same rating using HttpPost method.");
                }

                TblRating tblRating = new TblRating()
                {
                    Id = ratingId,
                    TblRestaurantId        = restaurantRating.RestaurantId,
                    Rating                 = restaurantRating.rating,
                    Comments               = restaurantRating.user_Comments,
                    RecordTimeStampCreated = DateTime.Now.AddDays(-1),
                    RecordTimeStampUpdated = DateTime.Now
                };
                _dbContext.Update(tblRating);

                return(SaveChanges());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public void AddRestaurantRating_WrongInput_RestaurantIdDoesntExist()
        {
            //Arrange
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 100,
                RatingId      = 0,
                rating        = "9",
                user_Comments = "Good place to eat"
            };
            Exception exception          = new Exception("Restaurant doesn't exist! Try sending a valid Restaurant Id");
            var       mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.AddRestaurantRating(restauratRatings, out restauratRatings)).Throws(exception);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.AddRestaurantRating(restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(400, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, exception.Message);
        }
        public void AddRestaurantRating_WrongInput_RestaurantIdLessThanOne()
        {
            //Arrange
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 0,
                RatingId      = 0,
                rating        = "9",
                user_Comments = "Good place to eat"
            };
            Exception exception          = new Exception("Entity Error : Restaurant Id cannot be less than one");
            var       mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.AddRestaurantRating(restauratRatings, out restauratRatings)).Throws(exception);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.AddRestaurantRating(restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(400, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, exception.Message);
        }
        public void UpdateRestaurantRating_WrongInput_RatingIsEmpty()
        {
            //Arrange
            int ratingId = 1;
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                RatingId      = 1,
                rating        = string.Empty,
                user_Comments = "Good place to eat"
            };
            Exception exception          = new Exception("Entity Error : Rating cannot be empty");
            var       mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.UpdateRestaurantRating(ratingId, restauratRatings)).Throws(exception);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.UpdateRestaurantRating(ratingId, restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(400, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, exception.Message);
        }
Beispiel #10
0
        public async Task <ActionResult> PostAsync([FromBody] RestaurantRating rating)
        {
            var userId = this.GetUserId();

            if (rating.ID > 0)
            {
                var savedRating = await context.RestaurantRatings.SingleOrDefaultAsync <RestaurantRating>(rr => rr.ID == rating.ID);

                if (savedRating == null) // Make sure there is a rating with that ID
                {
                    return(NotFound(rating));
                }
                if (savedRating.UserID != userId) // Make sure the user making the request can update this rating
                {
                    return(Unauthorized());
                }
                savedRating.RestaurantName = rating.RestaurantName;
                savedRating.RestaurantType = rating.RestaurantType;
                savedRating.Rating         = rating.Rating;
                await context.SaveChangesAsync();

                return(Ok(rating));
            }
            else
            {
                rating.UserID = userId;
                await context.AddAsync <RestaurantRating>(rating);

                await context.SaveChangesAsync();

                return(CreatedAtAction("GetByIdAsync", rating));
            }
        }
Beispiel #11
0
        public void InvalidSubmitReview()
        {
            //Arrange
            RestaurantRating restaurantRatings = new RestaurantRating();

            restaurantRatings = null;
            var mockOrder  = new Mock <IReviewBusiness>();
            var mockOrder1 = new Mock <ILogService>();

            mockOrder.Setup(x => x.RestaurantRating(It.IsAny <RestaurantRating>()));
            mockOrder1.Setup(x => x.LogMessage("Invalid Submitted Reviews TestCase"));
            //Act
            var reviewcontroller = new ReviewController(mockOrder.Object, mockOrder1.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            reviewcontroller.ModelState.AddModelError("fakeError", "fakeError");
            var data            = reviewcontroller.ResturantRating(restaurantRatings);
            var badObjectResult = data as BadRequestResult;

            //Assert
            Assert.AreEqual(400, badObjectResult.StatusCode);
            Assert.IsNull(restaurantRatings);
        }
Beispiel #12
0
        public void ExceptionInvalidSubmitReview()
        {
            //Arrange
            RestaurantRating restaurantRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                customerId    = 1,
                rating        = 8,
                user_Comments = "Excellent",
            };
            var mockOrder  = new Mock <IReviewBusiness>();
            var mockOrder1 = new Mock <ILogService>();

            mockOrder.Setup(x => x.RestaurantRating(It.IsAny <RestaurantRating>()));
            mockOrder1.Setup(x => x.LogMessage("Exception in Submitted Reviews TestCase"));
            //Act
            var reviewcontroller = new ReviewController(mockOrder.Object, mockOrder1.Object);

            reviewcontroller.ControllerContext             = new ControllerContext();
            reviewcontroller.ControllerContext.HttpContext = new DefaultHttpContext();
            reviewcontroller.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "a";
            // reviewcontroller.ModelState.AddModelError("1", "Invalid Model");
            var data            = reviewcontroller.ResturantRating(restaurantRatings);
            var badObjectResult = data as ObjectResult;

            ////Assert
            Assert.AreEqual(500, badObjectResult.StatusCode);
        }
        public List <RestaurantRating> GetRestaurantRatings(int restaurantId)
        {
            if (restaurantId < 1)
            {
                throw new Exception("Restaurant Id cannot be less than one! Try again with input for Restaurant Id greater than or equals one");
            }

            try
            {
                IQueryable <DataLayer.DataEntity.RestaurantRating> restaurantRatingQueryable = _ratingRepository.GetRestaurantRatings(restaurantId);
                List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();
                if (restaurantRatingQueryable != null)
                {
                    foreach (var item in restaurantRatingQueryable)
                    {
                        RestaurantRating rating = new RestaurantRating()
                        {
                            RatingId      = item.RatingId,
                            RestaurantId  = item.RestaurantId,
                            rating        = item.rating,
                            user_Comments = item.user_Comments
                        };
                        restaurantRatings.Add(rating);
                    }
                }
                return(restaurantRatings);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public void UpdateRestaurantRating_ReturnedFalse()
        {
            //Arrange
            string           result           = "Error in updating restaurant! Try again after some time.";
            int              ratingId         = 1;
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                RatingId      = 1,
                rating        = "9",
                user_Comments = "Good place to eat"
            };
            var mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.UpdateRestaurantRating(ratingId, restauratRatings)).Returns(false);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.UpdateRestaurantRating(ratingId, restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(500, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, result);
        }
        public void UpdateRestaurantRating_UnexpectedException()
        {
            //Arrange
            int ratingId = 1000;
            RestaurantRating restauratRatings = new RestaurantRating()
            {
                RestaurantId  = 1,
                RatingId      = 1000,
                rating        = "9",
                user_Comments = "Good place to eat"
            };
            Exception exception          = new Exception("Error in updating restaurant! Try again after some time.");
            var       mockRatingBusiness = new Mock <IRatingBusiness>();

            mockRatingBusiness.Setup(x => x.UpdateRestaurantRating(ratingId, restauratRatings)).Throws(exception);

            //Act
            var ratingController = new RatingController(mockRatingBusiness.Object);
            var data             = ratingController.UpdateRestaurantRating(ratingId, restauratRatings);
            var okObjectResult   = data as ObjectResult;

            //Assert
            Assert.AreEqual(500, okObjectResult.StatusCode);
            Assert.IsNotNull(okObjectResult);
            Assert.AreEqual(okObjectResult.Value, exception.Message);
        }
        public void Rate(RestaurantRating restaurantRating)
        {
            Restaurant restaurant = _unitOfWork.RestaurantRepository.Get(
                r => (r.RestaurantId == restaurantRating.RestaurantId) && (r.Country == _userProfile.Country) && (r.City == _userProfile.City)
                ).FirstOrDefault();

            if (restaurant == null)
            {
                throw new EntityNotFoundException("Restaurant with id " + restaurantRating.RestaurantId + " not found.");
            }

            RestaurantRating existingRestaurantRating = _unitOfWork.RestaurantRatingRepository.Get(
                rr => (rr.UserProfileId == _userProfile.UserProfileId) && (rr.RestaurantId == restaurant.RestaurantId)
                ).FirstOrDefault();

            if (existingRestaurantRating == null)
            {
                restaurantRating.CreatedAt     = DateTime.Now;
                restaurantRating.UserProfileId = _userProfile.UserProfileId;

                _unitOfWork.RestaurantRatingRepository.Add(restaurantRating);
            }
            else
            {
                existingRestaurantRating.CreatedAt = DateTime.Now;
                existingRestaurantRating.Rating    = restaurantRating.Rating;

                _unitOfWork.RestaurantRatingRepository.Update(existingRestaurantRating);
            }

            _unitOfWork.Complete();
        }
 public IQueryable <RestaurantRating> GetRestaurantRating(int restaurantID)
 {
     try
     {
         List <RestaurantRating> restaurantRatings = new List <RestaurantRating>();
         IQueryable <TblRating>  rating;
         rating = search_Repository.GetRestaurantRating(restaurantID);
         foreach (var item in rating)
         {
             RestaurantRating ratings = new RestaurantRating
             {
                 rating        = item.Rating,
                 RestaurantId  = item.TblRestaurantId,
                 user_Comments = item.Comments,
                 customerId    = item.TblCustomerId,
             };
             restaurantRatings.Add(ratings);
         }
         return(restaurantRatings.AsQueryable());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public RestaurantRating Delete(RestaurantRating entity)
 {
     using (_connection = Utilities.GetProfiledOpenConnection())
     {
         _connection.Execute("Delete from RestaurantRatings where UserID = @UserID and RestaurantID = @RestaurantID", entity);
     }
     return entity;
 }
 public RestaurantRating Insert(RestaurantRating entity)
 {
     using (_connection = Utilities.GetProfiledOpenConnection())
     {
         var insert = _connection.Insert(entity);
         entity.Id = (int)insert;
         return entity;
     }
 }
Beispiel #20
0
        /// <summary>
        /// Description: This method calls a method in DAL to retrieve average rating for a restaurant
        /// </summary>
        /// <param name="id">A unique restaurant id</param>
        /// <returns>Average rating</returns>
        public RestaurantRating GetRatingAverageByRestaurantID(int id)
        {
            // Instantiate object
            RestaurantDAL lRestaurantDAL = new RestaurantDAL();

            // get average rating
            RestaurantRating lRating = lRestaurantDAL.GetRatingAverageByRestaurantID(id);

            return(lRating);
        }
        public void UpdateRestaurantRating(RestaurantRating restaurantRating)
        {
            var rating = _restaurantRatingRepository.FirstOrDefault(p => p.Id == restaurantRating.Id);

            if (rating == null) return;

            rating.Rating = restaurantRating.Rating;

            _restaurantRatingRepository.Update(rating);
            _restaurantRatingRepository.SaveChanges();
        }
        public IActionResult ResturantRating([FromQuery] RestaurantRating restaurantRating)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            business_Repo.RestaurantRating(restaurantRating);

            return(this.Ok("Submitted the reviewes"));
        }
Beispiel #23
0
 public void Post(RestaurantRating restaurantRating)
 {
     if (restaurantRating.Id == 0)
     {
         _restaurantRatingTask.AddRestaurantRating(restaurantRating);
     }
     else
     {
         _restaurantRatingTask.UpdateRestaurantRating(restaurantRating);
     }
 }
Beispiel #24
0
        public async Task <ActionResult> DeleteAsync(int id)
        {
            var ratingToDelete = new RestaurantRating {
                ID = id
            };

            context.RestaurantRatings.Attach(ratingToDelete);
            context.Entry(ratingToDelete).State = EntityState.Deleted;
            await context.SaveChangesAsync();

            return(Ok());
        }
        public void Nodata_Test_Rating_submit()
        {
            RestaurantRating reviewdetails = new RestaurantRating();

            reviewdetails = null;

            var mockOrder = new Mock <IReviewRepository>();

            mockOrder.Setup(x => x.RestaurantRating(It.IsAny <TblRating>())).Returns(1);
            var orderFoodActionObject = new ReviewBusiness(mockOrder.Object);
            var data = orderFoodActionObject.RestaurantRating(reviewdetails);

            Assert.AreEqual(0, data);
        }
Beispiel #26
0
        public void UpdateRestaurantRating(RestaurantRating restaurantRating)
        {
            var rating = _restaurantRatingRepository.FirstOrDefault(p => p.Id == restaurantRating.Id);

            if (rating == null)
            {
                return;
            }

            rating.Rating = restaurantRating.Rating;

            _restaurantRatingRepository.Update(rating);
            _restaurantRatingRepository.SaveChanges();
        }
        /// <summary>
        /// Recording the customer rating the restaurants
        /// </summary>
        /// <param name=""></param>
        public void RestaurantRating(RestaurantRating restaurantRating)
        {
            if (restaurantRating != null)
            {
                TblRating rating = new TblRating()
                {
                    Rating          = restaurantRating.rating,
                    TblRestaurantId = restaurantRating.RestaurantId,
                    Comments        = restaurantRating.user_Comments,
                    TblCustomerId   = restaurantRating.customerId
                };

                search_Repository.RestaurantRating(rating);
            }
        }
Beispiel #28
0
        public bool UpdateRestaurantRating(int ID, RestaurantRating restaurantRating)
        {
            if (restaurantRating != null)
            {
                TblRating rating = new TblRating()
                {
                    Rating        = restaurantRating.rating,
                    Comments      = restaurantRating.user_Comments,
                    TblCustomerId = restaurantRating.customerId,
                    UserModified  = restaurantRating.customerId
                };

                return(review_Repository.UpdateRestaurantRating(ID, rating));
            }
            return(false);
        }
        public bool Remove(RestaurantRatingDTO ratingDTO)
        {
            if (ratingDTO != null)
            {
                using (IEateryDbContext context = _unitOfWork.GetEateryDbContext())
                {
                    RestaurantRating rating = ObjectTypeConverter.Convert <RestaurantRatingDTO, RestaurantRating>(ratingDTO);

                    this._restaurantRatingRepository.Delete(context, rating);
                    _unitOfWork.Commit(context);

                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Recording the customer rating the restaurants
        /// </summary>
        /// <param name="restaurantRating"></param>
        public int RestaurantRating(RestaurantRating restaurantRating)
        {
            if (restaurantRating != null)
            {
                TblRating rating = new TblRating()
                {
                    Rating          = restaurantRating.rating,
                    TblRestaurantId = restaurantRating.RestaurantId,
                    Comments        = restaurantRating.user_Comments,
                    TblCustomerId   = restaurantRating.customerId
                };

                return(review_Repository.RestaurantRating(rating));
            }
            return(0);
        }
        public IActionResult UpdateResturantRating(int ID, [FromBody] RestaurantRating restaurantRating)
        {
            if ((!ModelState.IsValid) || ID <= 0)
            {
                return(this.BadRequest());
            }

            if (business_Repo.UpdateRestaurantRating(ID, restaurantRating))
            {
                return(this.Ok("Updated the reviewes"));
            }
            else
            {
                return(this.StatusCode((int)HttpStatusCode.InternalServerError, "Unable to process request."));
            }
        }
        public IActionResult ResturantRating([FromBody] RestaurantRating restaurantRating)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            if (business_Repo.RestaurantRating(restaurantRating))
            {
                return(this.Ok("Submitted the reviewes"));
            }
            else
            {
                return(this.StatusCode((int)HttpStatusCode.InternalServerError, "Unable to process request."));
            }
        }
        public bool Add(RestaurantRatingDTO ratingDTO)
        {
            if (ratingDTO != null)
            {
                using (IEateryDbContext context = _unitOfWork.GetEateryDbContext())
                {
                    RestaurantRating rating = ObjectTypeConverter.Convert <RestaurantRatingDTO, RestaurantRating>(ratingDTO);
                    //rating.CreatedBy = ratingDTO.userID;
                    //rating.CreatedDate = DateTime.Now;

                    this._restaurantRatingRepository.Add(context, rating);
                    _unitOfWork.Commit(context);

                    return(true);
                }
            }
            return(false);
        }
        public void Invalid_Rating_submit()
        {
            RestaurantRating reviewdetails = new RestaurantRating()
            {
                customerId    = 1,
                rating        = 5,
                RestaurantId  = 1,
                user_Comments = "Good"
            };

            var mockOrder = new Mock <IReviewRepository>();

            mockOrder.Setup(x => x.RestaurantRating(It.IsAny <TblRating>())).Returns(0);
            var orderFoodActionObject = new ReviewBusiness(mockOrder.Object);
            var data = orderFoodActionObject.RestaurantRating(reviewdetails);

            Assert.AreEqual(0, data);
        }
 public ActionResult Save(RestaurantRating model)
 {
     model.UserId = CurrentUser.Id;
     model = _restaurantRatingLogic.Insert(model);
     return new JsonResult() {Data = model};
 }
 public void AddRestaurantRating(RestaurantRating restaurantRating)
 {
     _restaurantRatingRepository.Insert(restaurantRating);
     _restaurantRatingRepository.SaveChanges();
 }
 public RestaurantRating Insert(RestaurantRating entity)
 {
     _restaurantRatingRepository.Delete(entity);
     return _restaurantRatingRepository.Insert(entity);
 }