Ejemplo 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();
     }
 }
Ejemplo n.º 2
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.º 3
0
        public ActionResult Create(CreateRankingViewModel model)
        {
            try
            {
                rankingService.Create(model);
            }
            catch
            {

            }
            return RedirectToAction("Details","Place",new { id = model.PlaceId });
        }
Ejemplo n.º 4
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.º 5
0
 // GET: Ranking/Create
 public ActionResult Create(int id)
 {
     CreateRankingViewModel model = new CreateRankingViewModel { PlaceId = id, UserEmail = User.Identity.Name };
     ViewBag.PlaceId = id;
     return View(model);
 }
Ejemplo n.º 6
0
 public ActionResult SetRanking(CreateRankingViewModel model)
 {
     return View();
 }