Example #1
0
        public static void UpdateExerciseGameContestant(this ExerciseGameContestant contestant)
        {
            if (contestant == null)
            {
                return;
            }

            ThreadPool.QueueUserWorkItem(t =>
            {
                try
                {
                    using (var models = new ModelSource <UserProfile>())
                    {
                        if (contestant.Status == (int)Naming.GeneralStatus.Failed)
                        {
                            models.ExecuteCommand(@"UPDATE ExerciseGameRank
                                    SET        RankingScore = NULL, Rank = NULL
                                    WHERE   (UID = {0})", contestant.UID);
                        }

                        foreach (var item in models.GetTable <ExerciseGameItem>())
                        {
                            models.RefreshExerciseGameRank(item.ExerciseID);
                        }

                        models.RefreshPersonalRank();
                    }
                }
                catch (Exception ex)
                {
                    ApplicationLogging.LoggerFactory.CreateLogger(typeof(ExerciseGameExtensionMethods))
                    .LogError(ex, ex.Message);
                }
            });
        }
        public ActionResult CommitExerciseResult(ExerciseGameViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            var profile = HttpContext.GetUser();

            if (!viewModel.ExerciseID.HasValue)
            {
                ModelState.AddModelError("ExerciseID", "請選擇測驗項目!!");
            }

            if (!viewModel.Score.HasValue)
            {
                ModelState.AddModelError("Score", "請輸入純數字!!");
            }

            if (!viewModel.TestDate.HasValue)
            {
                ModelState.AddModelError("TestDate", "請選擇測驗日期!!");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = this.ModelState;
                return(View("~/Views/Shared/ReportInputError.ascx"));
            }

            ViewResult             result     = (ViewResult)EditExerciseResult(viewModel);
            ExerciseGameContestant contestant = result.Model as ExerciseGameContestant;

            if (contestant == null)
            {
                return(result);
            }

            if (contestant.Status != (int)Naming.GeneralStatus.Successful)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "參賽者已退賽!!"));
            }

            var item = new ExerciseGameResult
            {
                UID        = contestant.UID,
                Score      = viewModel.Score.Value,
                ExerciseID = viewModel.ExerciseID.Value,
                TestDate   = viewModel.TestDate.Value
            };

            models.GetTable <ExerciseGameResult>()
            .InsertOnSubmit(item);

            models.SubmitChanges();

            item.CheckExerciseGameRank();

            return(Json(new { result = true }));
        }
        public ActionResult ShowContestantRecord(ExerciseGameViewModel viewModel)
        {
            ViewResult             result = (ViewResult)EditExerciseResult(viewModel);
            ExerciseGameContestant item   = result.Model as ExerciseGameContestant;

            if (item != null)
            {
                result.ViewName = "~/Views/ExerciseGame/Module/ContestantRecord.ascx";
            }

            return(result);
        }
        public ActionResult CommitGameStatus(ExerciseGameViewModel viewModel)
        {
            ViewResult  result  = (ViewResult)GameIndex(viewModel);
            UserProfile profile = (UserProfile)result.Model;

            if (viewModel.Status == (int)Naming.GeneralStatus.Failed && !models.GetTable <ExerciseGameResult>().Any(u => u.UID == profile.UID))
            {
                models.ExecuteCommand("delete ExerciseGameContestant where UID = {0} ", profile.UID);
                models.RefreshExerciseGameContestant(null);
                return(result);
            }

            ExerciseGameContestant item = profile.ExerciseGameContestant;

            if (item == null)
            {
                item = profile.ExerciseGameContestant = new ExerciseGameContestant
                {
                    UserProfile = profile
                };
            }

            item.Status     = viewModel.Status;
            item.TotalScope = null;
            item.Rank       = null;

            if (item.ExerciseGameRank.Count == 0)
            {
                var exerciseItem = models.GetTable <ExerciseGameItem>().FirstOrDefault();
                if (exerciseItem != null)
                {
                    item.ExerciseGameRank.Add(new ExerciseGameRank
                    {
                        ExerciseID = exerciseItem.ExerciseID
                    });
                }
            }
            models.SubmitChanges();

            models.RefreshExerciseGameContestant(item);

            return(result);
        }
Example #5
0
        public static void RefreshExerciseGameContestant(this GenericManager <BFDataContext> models, ExerciseGameContestant contestant)

        {
            try
            {
                if (contestant != null && contestant.Status == (int)Naming.GeneralStatus.Failed)
                {
                    models.ExecuteCommand(@"UPDATE ExerciseGameRank
                                    SET        RankingScore = NULL, Rank = NULL
                                    WHERE   (UID = {0})", contestant.UID);
                }

                foreach (var item in models.GetTable <ExerciseGameItem>())
                {
                    models.RefreshExerciseGameRank(item.ExerciseID);
                }

                models.RefreshPersonalRank();
            }
            catch (Exception ex)
            {
                ApplicationLogging.LoggerFactory.CreateLogger(typeof(ExerciseGameExtensionMethods))
                .LogError(ex, ex.Message);
            }
        }
        public static void RefreshExerciseGameContestant <TEntity>(this ModelSource <TEntity> models, ExerciseGameContestant contestant)
            where TEntity : class, new()
        {
            try
            {
                if (contestant != null && contestant.Status == (int)Naming.GeneralStatus.Failed)
                {
                    models.ExecuteCommand(@"UPDATE ExerciseGameRank
                                    SET        RankingScore = NULL, Rank = NULL
                                    WHERE   (UID = {0})", contestant.UID);
                }

                foreach (var item in models.GetTable <ExerciseGameItem>())
                {
                    models.RefreshExerciseGameRank(item.ExerciseID);
                }

                models.RefreshPersonalRank();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }