예제 #1
0
파일: MashController.cs 프로젝트: pmn4/mash
        public ActionResult Mash(MashViewModel viewModel)
        {
            var choice = viewModel.Media.FirstOrDefault(m => m.MediaId == viewModel.ChoiceMediaId);
            if (choice == null)
            {
                return Json(new { success = true }, JsonRequestBehavior.AllowGet);
            }

            var success = EloRatingSystem.UpdateRatings(viewModel);

            if(success)
                success = _dataProvider.Mash(viewModel);

            foreach(var m in viewModel.Media.Where(m => m.Rating.HasValue))
            {
                m.CurrentRating = m.Rating.Value; // nice try resharper
                m.Rating = null;
            }

            if (ControllerContext.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                return Json(new
                {
                    success,
                }, JsonRequestBehavior.AllowGet);
            }

            return new RedirectResult(Url.RouteUrl("Default"));
        }
예제 #2
0
파일: DataProvider.cs 프로젝트: pmn4/mash
		public bool UpdateMashAddRating(MashViewModel mash)
		{
			var sql = String.Format(
				"UPDATE mashup SET mediaa = {0}, mediaarating = {1}, mediab = {2}, mediabrating = {3}, choice = {4} WHERE inx = {5};",
				mash.Media.ElementAt(0).MediaId,
				mash.Media.ElementAt(0).CurrentRating,
				mash.Media.ElementAt(1).MediaId,
				mash.Media.ElementAt(1).CurrentRating,
				mash.ChoiceMediaId,
				mash.MashId);

			var command = new MySqlCommand(sql, _conn);
			var mashResult = command.ExecuteNonQuery() > 0;
			var mediaA = mash.Media.ElementAt(0);
			var mediaB = mash.Media.ElementAt(1);

			sql =
				String.Format(
					"INSERT INTO rating (type, media, rating, increase, mashup) VALUES ('{0}', {1}, {2}, {3}, {4}), ('{5}', {6}, {7}, {8}, {9});",
					mediaA.RatingType,
					mediaA.MediaId,
					mediaA.Rating,
					mediaA.CurrentRating - mediaA.Rating,
					mash.MashId,
					mediaB.RatingType,
					mediaB.MediaId,
					mediaB.Rating,
					mediaB.CurrentRating - mediaB.Rating,
					mash.MashId);
			command.Dispose();
			command = new MySqlCommand(sql, _conn);

			return mashResult && command.ExecuteNonQuery() > 0;
		}
예제 #3
0
파일: DataProvider.cs 프로젝트: pmn4/mash
		public bool Mash(MashViewModel mash)
		{
			var sql = String.Format(
				"INSERT INTO mashup(mediaa, mediaarating, mediab, mediabrating, choice, timestamp) VALUES({0}, {1}, {2}, {3}, {4}, CURRENT_TIMESTAMP);",
				mash.Media.ElementAt(0).MediaId,
				mash.Media.ElementAt(0).CurrentRating,
				mash.Media.ElementAt(1).MediaId,
				mash.Media.ElementAt(1).CurrentRating,
				mash.ChoiceMediaId);

			var command = new MySqlCommand(sql, _conn);
			var mashResult = command.ExecuteNonQuery() > 0;
			var mashId = command.LastInsertedId;
			var mediaA = mash.Media.ElementAt(0);
			var mediaB = mash.Media.ElementAt(1);

			sql =
				String.Format(
					"INSERT INTO rating (type, media, rating, increase, mashup) VALUES ('{0}', {1}, {2}, {3}, {4}), ('{5}', {6}, {7}, {8}, {9});",
					mediaA.RatingType,
					mediaA.MediaId,
					mediaA.Rating,
					mediaA.CurrentRating - mediaA.Rating,
					mashId,
					mediaB.RatingType,
					mediaB.MediaId,
					mediaB.Rating,
					mediaB.CurrentRating - mediaB.Rating,
					mashId);
			command.Dispose();
			command = new MySqlCommand(sql, _conn);

			return mashResult && command.ExecuteNonQuery() > 0;
		}