示例#1
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);
            }
        }
示例#2
0
        public bool EditResturantReview(RestaurantReview restaurantReview)
        {
            try
            {
                // RestaurantReview EditedResult = new RestaurantReview();
                var Users = _connection.TblRating.Where(e => e.TblRestaurantId == restaurantReview.RestaurantId && e.TblCustomerId == restaurantReview.CustomerId).ToList();

                // RestaurantReview editedUser = new RestaurantReview();
                if (Users.Count == 0)
                {
                    return(false);
                }
                else
                {
                    List <TblRating> usertobeedited                        = _connection.TblRating.Where(x => x.Id == restaurantReview.Id).ToList();
                    usertobeedited.FirstOrDefault().Rating                 = (restaurantReview.Rating);
                    usertobeedited.FirstOrDefault().RecordTimeStamp        = usertobeedited.FirstOrDefault().RecordTimeStamp;
                    usertobeedited.FirstOrDefault().RecordTimeStampCreated = usertobeedited.FirstOrDefault().RecordTimeStampCreated;
                    usertobeedited.FirstOrDefault().Comments               = restaurantReview.Comments;
                    _connection.Update(usertobeedited.FirstOrDefault());
                    _connection.SaveChanges();
                    //editedUser = restaurantReview;
                }
                #region Comments
                //foreach (var User in Users)
                //{
                //    //if (Users.Count == 1)
                //    //{
                //    if (User.Id == restaurantReview.Id)
                //    {
                //        _connection.Entry(
                //            new TblRating
                //            {
                //                Rating = restaurantReview.Rating,
                //                UserModified = restaurantReview.UserModified,
                //                Comments = restaurantReview.Comments,
                //                 RecordTimeStamp=User.RecordTimeStamp,
                //                RecordTimeStampCreated=User.RecordTimeStampCreated}).State = EntityState.Added;
                //    this._connection.TblRating.Add(new TblRating
                //    {
                //        Rating = restaurantReview.Rating,
                //        UserModified = restaurantReview.UserModified,
                //        Comments = restaurantReview.Comments,
                //        RecordTimeStamp = User.RecordTimeStamp,
                //        RecordTimeStampCreated = User.RecordTimeStampCreated
                //    });


                //    _connection.SaveChanges();
                //        // RestaurantReview editedUser = new RestaurantReview()
                //        editedUser.Comments = restaurantReview.Comments;
                //        editedUser.Id = restaurantReview.Id;
                //        editedUser.Rating = restaurantReview.Rating;
                //        editedUser.CustomerId = restaurantReview.CustomerId;
                //        editedUser.UserCreated = restaurantReview.UserCreated;
                //        editedUser.UserModified = restaurantReview.UserModified;
                //        editedUser.RestaurantId = restaurantReview.RestaurantId ;

                //        return editedUser;
                //    }
                //    //}
                //    //else
                //    //{
                //    //    foreach(var MutliUser in Users)
                //    //    {
                //    //        if(MutliUser.Id==User.Id)
                //    //        {
                //    //            _connection.Entry(User).State = EntityState.Modified;

                //    //            _connection.SaveChanges();
                //    //            RestaurantReview editedUser = new RestaurantReview() { Comments = User.Comments, Id = User.Id, Rating = User.Rating, CustomerId = User.TblCustomerId, UserCreated = User.UserCreated, UserModified = User.UserModified, RestaurantId = User.TblRestaurantId };
                //    //            EditedResult.Add(editedUser);
                //    //            break;
                //    //        }
                //    //    }
                //    //}

                //}
                #endregion
                return(true);


                //return EditedResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }