/// <summary> /// AddToFavourite /// </summary> /// <param name="_businessVM"></param> /// <returns></returns> public FavouritePlaceVM AddToFavourite(FavouritePlaceVM _favouritePlaceVM) { FavouritePlace _favouritePlace = new FavouritePlace { UserID = _favouritePlaceVM.UserID }; if (string.IsNullOrEmpty(_favouritePlaceVM.PlaceID)) { _favouritePlace.BusinessID = _favouritePlaceVM.BusinessID; _favouritePlace.PlaceID = null; } else { _favouritePlace.BusinessID = null; _favouritePlace.PlaceID = _favouritePlaceVM.PlaceID; } _favouritePlace = _objBusinessDAL.AddToFavourite(_favouritePlace, _favouritePlaceVM.IsFavourite); if (_favouritePlace != null) { _favouritePlaceVM.FavouritePlaceID = _favouritePlace.FavouritePlaceID; return(_favouritePlaceVM); } else { return(null); } }
/// <summary> /// AddToFavourite /// </summary> /// <param name="_businessVM"></param> /// <returns></returns> public FavouritePlaceVM AddToFavourite(FavouritePlaceVM _favouritePlaceVM) { FavouritePlace _favouritePlace = new FavouritePlace { UserID = _favouritePlaceVM.UserID }; _favouritePlace = _objBusinessDAL.AddToFavourite(_favouritePlace, _favouritePlaceVM.BusinessID, _favouritePlaceVM.IsFavourite); if (_favouritePlace != null) { _favouritePlaceVM.FavouritePlaceID = _favouritePlace.FavouritePlaceID; _favouritePlaceVM.BusinessID = _favouritePlace.BusinessID; /// need to check... return(_favouritePlaceVM); } else { return(null); } }
/// <summary> /// Convert FavouritePlace to FavouritePlace View Model Object /// </summary> /// <param name="item"></param> /// <returns></returns> private FavouritePlaceVM MakeFavouritePlaceVM(FavouritePlace item) { _objFavouritePlaceVM = new FavouritePlaceVM() { FavouritePlaceID = item.FavouritePlaceID, UserID = item.Business.UserID, BusinessID = item.BusinessID, BusinessName = item.Business.BusinessName, Latitude = item.Business.Latitude, Longitude = item.Business.Longitude, Location = item.Business.Location, ContactNo = item.Business.ContactNo, Website = item.Business.Website, StartTime = item.Business.StartTime, EndTime = item.Business.EndTime, Flavours = item.Business.Flavours, IsFavouritePlace = 1 }; // Add Business Rating Double _averageRating = 0; if (item.Business.BusinessRatings.Count > 0) { List <BusinessRatingVM> lstBusinessRating = new List <BusinessRatingVM>(); foreach (var rating in item.Business.BusinessRatings) { BusinessRatingVM _businessRatingVM = new BusinessRatingVM { BusinessRatingID = rating.BusinessRatingID, BusinessID = rating.BusinessID, Rating = rating.Rating.ToString(), Review = rating.Review, UserID = rating.UserID, UserName = rating.User.UserName, ProfileImageUrl = rating.User.ProfileImageUrl }; lstBusinessRating.Add(_businessRatingVM); _averageRating = _averageRating + rating.Rating; } _objFavouritePlaceVM.Reviews = new JavaScriptSerializer().Serialize(lstBusinessRating); _averageRating = _averageRating / item.Business.BusinessRatings.Count; } else { _objFavouritePlaceVM.Reviews = "[]"; } _objFavouritePlaceVM.AverageRating = _averageRating; // Add Business Images if (item.Business.BusinessImages.Count > 0) { List <BusinessImageVM> lstBusinessImage = new List <BusinessImageVM>(); string tempDocUrl = ConfigurationManager.AppSettings["APIURL"]; foreach (var image in item.Business.BusinessImages) { BusinessImageVM _businessImageVM = new BusinessImageVM { BusinessImageID = image.BusinessImageID, BusinessID = image.BusinessID, ImageName = image.ImageName, ImageType = image.ImageType, ImagePath = tempDocUrl + "/Uploads/Business/" + image.BusinessID + "/" + image.ImageName }; lstBusinessImage.Add(_businessImageVM); } _objFavouritePlaceVM.Images = new JavaScriptSerializer().Serialize(lstBusinessImage); } else { _objFavouritePlaceVM.Images = "[]"; } return(_objFavouritePlaceVM); }