Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
 public void Create(CountryModel model)
 {
     using (var db = new DBEntitiesProxy())
     {
         db.Country.Add(new Country()
         {
             Name = model.Name,
             Code = model.Code,
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 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();
     }
 }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
 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();
     }
 }
Ejemplo n.º 10
0
 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();
     }
 }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        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();
            }
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
 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();
     }
 }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
 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;
     }
 }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
0
 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();
 }
Ejemplo n.º 19
0
 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();
 }
Ejemplo n.º 20
0
 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();
     }
 }
Ejemplo n.º 21
0
 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();
 }
Ejemplo n.º 22
0
 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();
     }
 }