public List<CreateCommentViewModel> GetCommentByPlace(int id) { using (var db = new DBEntitiesProxy()) { return db.COMMENT.Select(x => new CreateCommentViewModel { CommentId = x.CommentId, Content = x.Content, Date = x.Date, UserId = x.UserId, PlaceId = x.PlaceId, UserEmail = x.User.Email }).Where(x => x.PlaceId == id).ToList(); } }
public void Create(CreateRankingViewModel model) { using (var db = new DBEntitiesProxy()) { var userId = db.User.Where(x => x.Email == model.UserEmail).Select(x => x.UserId).Single(); db.Ranking.Add(new Ranking { Score = model.Score, PlaceId = model.PlaceId, UserId = userId }); var list = db.Ranking.Where(x => x.PlaceId == model.PlaceId).Select(x => x.Score).ToList(); double avg = model.Score; if (list.Count>0) { avg = list.Average(); } var place = db.Place.Where(x => x.PlaceId == model.PlaceId).SingleOrDefault(); if (place != null) { place.Ranking = Convert.ToInt32(avg); } db.SaveChanges(); } }
public int GetScoreByPlaceId(int id) { using (var db = new DBEntitiesProxy()) { var score = db.Ranking.Where(x => x.PlaceId == id).Select(x => x.Place.Ranking).SingleOrDefault(); if (score != null) return score.Value; else return 0; } }
public List<TravelsByUserViewModel> GetByUser(int id) { using (var db = new DBEntitiesProxy()) { var travels = db.Travels .Where(x => x.UserId == id) .Select(x => new TravelsByUserViewModel { Place = x.Place.Name, PlaceId = x.PlaceId }) .ToList(); return travels; } }
public int GetScoreByUser(CreateRankingViewModel model) { using (var db = new DBEntitiesProxy()) { var userId = db.User.Where(x => x.Email == model.UserEmail).Select(x => x.UserId).Single(); var score = db.Ranking.Where(x => x.PlaceId == model.PlaceId && x.UserId == userId) .Select(x => x.Place.Ranking).SingleOrDefault(); if (score != null) return score.Value; else return 0; } }
public void Create(CountryModel model) { using (var db = new DBEntitiesProxy()) { db.Country.Add(new Country() { Name = model.Name, Code = model.Code, }); db.SaveChanges(); } }
public void RemoveVisit(int placeId, string userEmail) { using (var db = new DBEntitiesProxy()) { var visits = db.Travels .Where(x => x.PlaceId == placeId && x.User.Email.Trim() == userEmail).ToList(); foreach (var v in visits) { db.Travels.Remove(v); } db.SaveChanges(); } }
public void Accept(int id) { using (var db = new DBEntitiesProxy()) { var place = db.Place.Where(x => x.PlaceId == id).SingleOrDefault(); if (place != null) { place.IsAccepted = true; } db.SaveChanges(); } }
public void Create(CreateTravelViewModel model) { using (var db = new DBEntitiesProxy()) { var userId = db.User.Where(x => x.Email == model.UserEmail).Select(x => x.UserId).Single(); db.Travels.Add(new Travels { Date = model.Date, PlaceId = model.PlaceId, UserId = userId }); db.SaveChanges(); } }
public void Create(CreateCommentViewModel model) { var userModel = new UserModel(); using (var db = new DBEntitiesProxy()) { db.COMMENT.Add(new COMMENT() { Content = model.Content, PlaceId = model.PlaceId, Date = System.DateTime.Now, UserId = userModel.GetUserID(model.UserEmail) }); db.SaveChanges(); } }
public void UpdateRanking(CreateRankingViewModel model) { using (var db = new DBEntitiesProxy()) { var userId = db.User.Where(x => x.Email == model.UserEmail).Select(x => x.UserId).Single(); var score = db.Ranking.Where(x => x.PlaceId == model.PlaceId && x.UserId == userId) .SingleOrDefault(); score.Score = model.Score; var avg = db.Ranking.Where(x => x.PlaceId == model.PlaceId).Select(x => x.Score).ToList().Average(); var place = db.Place.Where(x => x.PlaceId == model.PlaceId).SingleOrDefault(); if (place != null) { place.Ranking = Convert.ToInt32(avg); } db.SaveChanges(); } }
public void Create(CreatePlaceViewModel model) { var userModel = new UserModel(); using (var db = new DBEntitiesProxy()) { var userid = userModel.GetUserID(model.UserEmail); db.Place.Add(new Place() { Name = model.Name, Content = model.Content, Photo_URI = model.Photo_URI, CountryId = model.CountryId, IsAccepted = false, UserId = userid, AddDate = System.DateTime.Now, Ranking = 1, ContentPL = model.ContentPL, ContentPT = model.ContentPT, }); db.SaveChanges(); } }
public EditPlaceViewModel GetPlaceToEdit(int id) { using (var db = new DBEntitiesProxy()) { var place = db.Place.Select(x => new EditPlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Content = x.Content, ContentPL = x.ContentPL, ContentPT = x.ContentPT, CountryId = x.Country.CountryId, Photo_URI = x.Photo_URI }).Where(x => x.PlaceId == id).SingleOrDefault(); place.Countries = new List<CountryModel>(); place.Countries = db.Country.Select(x => new CountryModel { Code = x.Code, CountryId = x.CountryId, Name = x.Name }).ToList(); return place; } }
public List<CommentModel> GetComments() { using (var db = new DBEntitiesProxy()) { return db.COMMENT.Select(x => new CommentModel { CommentId = x.CommentId, Content = x.Content, Date = x.Date, UserId = x.UserId, PlaceId = x.PlaceId }).ToList(); } }
public CreatePlaceViewModel GetCountriesForCreate() { CreatePlaceViewModel model = new CreatePlaceViewModel(); model.Countries = new List<CountryModel>(); using (var db = new DBEntitiesProxy()) { model.Countries = db.Country.Select(x => new CountryModel { Code = x.Code, CountryId = x.CountryId, Name = x.Name }).ToList(); } return model; }
public PlaceListViewModel GetListOfPlaces(int coutryId) { using (var db = new DBEntitiesProxy()) { var places = new PlaceListViewModel(); places.Places = db.Place.Where(x => x.IsAccepted == true && x.CountryId == coutryId).OrderByDescending(x => x.AddDate).Select(x => new PlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Country = x.Country.Name }).ToList(); places.Countries = new List<CountryModel>(); places.Countries = db.Country.Select(x => new CountryModel { Code = x.Code, CountryId = x.CountryId, Name = x.Name }).ToList(); return places; } }
public void EditPlace(EditPlaceViewModel model) { using (var db = new DBEntitiesProxy()) { var place = db.Place.Where(x => x.PlaceId == model.PlaceId).Single(); place.Name = model.Name; place.Content = model.Content; place.Photo_URI = model.Photo_URI; place.CountryId = model.CountryId; place.ContentPL = model.ContentPL; place.ContentPT = model.ContentPT; db.Entry(place).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public List<CountryModel> GetCountries() { var db = new DBEntitiesProxy(); return db.Country.Select(x => new CountryModel { Code = x.Code, CountryId = x.CountryId, Name = x.Name }).ToList(); }
public List<PlaceViewModel> GetPlacesByRanking() { var db = new DBEntitiesProxy(); return db.Place.Where(x => x.IsAccepted == true).OrderByDescending(x => x.Ranking.Value).Select(x => new PlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Content = x.Content, UserName = x.User.FirstName + " " + x.User.LastName, Country = x.Country.Name, Photo_URI = x.Photo_URI }).Take(4).ToList(); }
public List<PlaceViewModel> GetPlacesAddedByUser(string email) { using (var db = new DBEntitiesProxy()) { return db.Place.Where(x => x.User.Email == email).Select(x => new PlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Content = x.Content, UserName = x.User.FirstName + " " + x.User.LastName, Country = x.Country.Name, Photo_URI = x.Photo_URI }).ToList(); } }
public List<PlaceViewModel> GetPlaces() { var db = new DBEntitiesProxy(); return db.Place.Select(x => new PlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Content = x.Content, UserName = x.User.FirstName + " " + x.User.LastName, Country = x.Country.Name, Photo_URI = x.Photo_URI, IsAccepted = x.IsAccepted }).ToList(); }
public PlaceViewModel GetPlace(int id) { using (var db = new DBEntitiesProxy()) { return db.Place.Select(x => new PlaceViewModel { PlaceId = x.PlaceId, Name = x.Name, Content = x.Content, ContentPL = x.ContentPL, ContentPT = x.ContentPT, UserEmail = x.User.Email, UserName = x.User.FirstName + " " + x.User.LastName, Country = x.Country.Name, Photo_URI = x.Photo_URI, Score = (int)x.Ranking, IsAccepted = x.IsAccepted }).Where(x => x.PlaceId == id).SingleOrDefault(); } }