public bool PostYourReview(TblTableReview tblTableReview)
        {
            if (tblTableReview != null)
            {
                db.Add(tblTableReview);
                db.SaveChanges();
                return(true);
            }

            return(false);
        }
Beispiel #2
0
 private bool SaveChanges()
 {
     try
     {
         _dbContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Beispiel #3
0
 public IQueryable <TblRating> UpdateReviewRating(ReviewRating reviewRating)
 {
     try
     {
         if (dbContext != null)
         {
             var updateRecord = from rating in dbContext.TblRating
                                where rating.TblRestaurantId == reviewRating.RestaurantID
                                select rating;
             foreach (var items in updateRecord)
             {
                 if (items.TblRestaurantId == reviewRating.RestaurantID &&
                     items.TblCustomerId == reviewRating.CustomerId)
                 {
                     items.Rating   = reviewRating.Rating;
                     items.Comments = reviewRating.ReviewComments;
                     items.RecordTimeStampCreated = DateTime.Now;
                 }
             }
             dbContext.SaveChanges();
             return((from rating in dbContext.TblRating
                     join restaurant in dbContext.TblRestaurant on
                     rating.TblRestaurantId equals restaurant.Id
                     where rating.TblRestaurantId == reviewRating.RestaurantID && rating.TblCustomerId == reviewRating.CustomerId
                     select new TblRating
             {
                 Rating = rating.Rating,
                 Comments = rating.Comments,
                 TblRestaurantId = restaurant.Id,
                 TblRestaurant = restaurant,
                 TblCustomerId = rating.TblCustomerId
             }).AsQueryable());
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Recording the customer rating the restaurants
        /// </summary>
        /// <param name="tblRating"></param>
        public int RestaurantRating(TblRating tblRating)
        {
            TblRating tr = db.TblRating.Where(r => r.TblRestaurantId == tblRating.TblRestaurantId && r.TblCustomerId == tblRating.TblCustomerId).FirstOrDefault();

            if (tr != null)
            {
                tr.Comments               = tblRating.Comments;
                tr.Rating                 = tblRating.Rating;
                tr.RecordTimeStamp        = DateTime.Now;
                tr.RecordTimeStampCreated = DateTime.Now;
                tr.TblCustomerId          = tblRating.TblCustomerId;
                tr.TblRestaurantId        = tblRating.TblRestaurantId;
                db.SaveChanges();
                return(tr.Id);
            }
            else
            {
                db.Set <TblRating>().Add(tblRating);
                db.SaveChanges();
                return(tblRating.Id);
            }
        }
Beispiel #5
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;
            }
        }