Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
0
 public void Create(CountryModel model)
 {
     using (var db = new DBEntitiesProxy())
     {
         db.Country.Add(new Country()
         {
             Name = model.Name,
             Code = model.Code,
         });
         db.SaveChanges();
     }
 }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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();
     }
 }
Exemplo n.º 6
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();
     }
 }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
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();
            }
        }
Exemplo n.º 9
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();
            }
        }