Esempio n. 1
0
        public ActionResult StartContest(int id, ContestModel collection)
        {
            int   socau    = tn.ch_db.Count(x => x.MaDe == id);
            float hesodiem = 100 / socau;
            float diem;
            int   bodem = 0;

            for (int i = 0; i < collection.ListQuiz.Count; i++)
            {
                var quizid = tn.Quizs.Find(collection.ListQuiz[i].MaCauHoi);
                if (quizid.DapAn == collection.ListQuiz[i].SelectedAnswer)
                {
                    bodem = bodem + 1;
                }
            }
            diem = bodem * hesodiem;
            var session = (TracNghiemLTK.Common.ThiSinhInfo)Session[TracNghiemLTK.Common.CommonConstantsStudent.STUDENT_SESSION];

            tn.KetQuas.Add(new KetQua()
            {
                MaDe      = id,
                MaThiSinh = session.MaThiSinh,
                Diem      = diem,
                NgayThi   = DateTime.Now
            });
            tn.SaveChanges();
            return(RedirectToAction("Index", "ContestResult", new { area = "Contest", @maThiSinh = session.MaThiSinh, @maDe = id }));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StartDate,Duration,Active")] ContestModel contestModel)
        {
            if (id != contestModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    contestModel.ApplicationUserId = _userManager.GetUserId(User);
                    _context.Update(contestModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContestModelExists(contestModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contestModel));
        }
        public ActionResult ViewContests()
        {
            DBController dbController = new DBController();
            DataTable    dt           = dbController.SelectContests();

            if (dt == null)
            {
                return(RedirectToAction("EmptyContests"));
            }

            List <ContestModel> Contests = new List <ContestModel>();

            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ContestModel Contest = new ContestModel();
                Contest.ContestID     = Convert.ToInt16(dt.Rows[i]["ContestID"]);
                Contest.ContestName   = Convert.ToString(dt.Rows[i]["ContestName"]);
                Contest.ContestDate   = Convert.ToDateTime(dt.Rows[i]["ContestDate"]);
                Contest.ContestLength = int.Parse(Convert.ToString(dt.Rows[i]["ContestLength"]));

                Contest.ContestWriterID = int.Parse(Convert.ToString(dt.Rows[i]["ContestWriter"]));
                DataTable WriterName = dbController.SelectUserNameByID(Contest.ContestWriterID);
                Contest.ContestWriterName = Convert.ToString(WriterName.Rows[0]["Fname"]) + " " +
                                            Convert.ToString(WriterName.Rows[0]["Lname"]);

                Contests.Add(Contest);
            }

            return(View(Contests));
        }
Esempio n. 4
0
        public ActionResult Post(ContestModel contest)
        {
            if (!ModelState.IsValid)
            {
                return(View("add", contest));
            }

            if (contest.ParticipationEndTime == null && contest.MaxParticipationsCount == null)
            {
                ModelState.AddModelError("", "You have to choose end date or max pariticpations count");
                return(View("add", contest));
            }

            var userId     = User.Identity.GetUserId();
            var newContest = new Contest()
            {
                Title                  = contest.Title,
                Description            = contest.Description,
                CreatedOn              = DateTime.Now,
                DeadlineStrategy       = contest.DeadlineStrategy,
                MaxParticipationsCount = contest.MaxParticipationsCount,
                OwnerId                = userId,
                ParticipationEndTime   = contest.ParticipationEndTime,
                ParticipationStrategy  = contest.ParticipationStrategy,
                PossibleWinnersCount   = contest.PossibleWinnersCount,
                State                  = TypeOfEnding.Ongoing,
                VotingStrategy         = contest.VotingStrategy,
                LastUpdated            = DateTime.Now
            };

            this.Data.Contests.Add(newContest);
            this.Data.SaveChanges();

            return(RedirectToAction("Index", "Prize", new { ContestId = newContest.Id, countOfPrizes = newContest.PossibleWinnersCount }));
        }
Esempio n. 5
0
        public void TestPostAction_ShouldRedirectToGetUserContests()
        {
            var contest = new ContestModel()
            {
                Description          = "test",
                PossibleWinnersCount = 2,
                Title = "testov",
                MaxParticipationsCount = 10
            };

            var identity = new GenericIdentity("as");

            identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "0"));
            var controller          = new ContestController(new PhotoContestDataMock());
            var controllerContext   = new TestableControllerContext();
            var principal           = new GenericPrincipal(identity, null);
            var testableHttpContext = new TestableHttpContext
            {
                User = principal
            };

            controllerContext.HttpContext = testableHttpContext;
            controller.ControllerContext  = controllerContext;
            var result = (RedirectToRouteResult)controller.Post(contest);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Prize", result.RouteValues["controller"]);
        }
Esempio n. 6
0
        public ActionResult ViewGroupContests(int GroupId, int id = 0, string UserName = "")
        {
            DBController db = new DBController();
            DataTable    dt = db.SelectGroupContests(GroupId);

            List <ContestModel> Contests = new List <ContestModel>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ContestModel CM = new ContestModel
                {
                    ContestName     = Convert.ToString(dt.Rows[i]["ContestName"]),
                    ContestLength   = Convert.ToInt32(dt.Rows[i]["ContestLength"]),
                    ContestDate     = Convert.ToDateTime(dt.Rows[i]["ContestDate"]),
                    ContestWriterID = Convert.ToInt32(dt.Rows[i]["ContestWriter"])
                };
                CM.ContestWriterName = Convert.ToString(db.SelectUserNameByID(CM.ContestWriterID).Rows[0]["Fname"]) +
                                       " " +
                                       Convert.ToString(db.SelectUserNameByID(CM.ContestWriterID).Rows[0]["Lname"]);
                Contests.Add(CM);
            }

            ViewBag.GroupId  = GroupId;
            ViewBag.id       = id;
            ViewBag.UserName = UserName;
            return(View(Contests));
        }
Esempio n. 7
0
        public ActionResult ViewMyContests(int id = 0, string UserName = "")
        {
            if (id == 0)
            {
                return(RedirectToAction("MustSignIn"));
            }

            DBController        dbController = new DBController();
            DataTable           dt           = dbController.SelectMyContests(id);
            List <ContestModel> list         = new List <ContestModel>();

            if (dt == null)
            {
                return(RedirectToAction("EmptyContests"));
            }
            for (int i = 0; i < dt.Rows.Count; ++i)
            {
                Models.ContestModel Contest = new ContestModel();
                Contest.ContestID     = Convert.ToInt16(dt.Rows[i]["ContestID"]);
                Contest.ContestName   = Convert.ToString(dt.Rows[i]["ContestName"]);
                Contest.ContestDate   = Convert.ToDateTime(dt.Rows[i]["ContestDate"]);
                Contest.ContestLength = int.Parse(Convert.ToString(dt.Rows[i]["ContestLength"]));

                Contest.ContestWriterID = int.Parse(Convert.ToString(dt.Rows[i]["ContestWriter"]));
                DataTable WriterName = dbController.SelectUserNameByID(Contest.ContestWriterID);
                Contest.ContestWriterName = Convert.ToString(WriterName.Rows[0]["Fname"]) + " " +
                                            Convert.ToString(WriterName.Rows[0]["Lname"]);

                list.Add(Contest);
            }

            ViewBag.id       = id;
            ViewBag.UserName = UserName;
            return(View(list));
        }
Esempio n. 8
0
        private static async Task <ContestResults> GetContest(string eventID)
        {
            APIService   srv              = new APIService();
            ContestModel model            = new ContestModel();
            Dictionary <string, string> p = new Dictionary <string, string>();

            p.Add("eventId", string.Format("'{0}'", eventID));

            model.CommandModel.SessionToken = await App.GetUsersSession();

            model.CommandModel.ServiceName = "Contest";
            model.CommandModel.Action      = "GetContestForEvent";
            model.CommandModel.Parameters  = p;

            ContestResults result = null;
            var            cache  = BlobCache.UserAccount;
            var            cachedContestsPromise = cache.GetAndFetchLatest(
                "contests",
                () => srv.GetContestsForEvent(model.CommandModel),
                offset =>
            {
                TimeSpan elapsed = DateTimeOffset.Now - offset;
                return(elapsed > new TimeSpan(hours: 0, minutes: 10, seconds: 0));
            });

            cachedContestsPromise.Subscribe(subscribedContests =>
            {
                result = subscribedContests;
            });

            result = await cachedContestsPromise.FirstOrDefaultAsync();

            return(result);
        }
        public async Task <ContestModel> Create(ContestModel data)
        {
            data.ID = Guid.NewGuid();
            var result = await this._repo.Add(data);

            return(result);
        }
        public IActionResult Edit(int id, ContestModel model)
        {
            // Accessible to Admins & Owners only
            if (!this.IsAdmin &&
                !this.IsOwner(id))
            {
                return(this.RedirectToContests());
            }

            // Validate model
            if (!this.IsValidModel(model))
            {
                this.ShowError(ContestError);
                this.GetContestViewData(model); // update post view data
                return(this.View());
            }

            // Update contest in db
            var result = this.contestService.Update(
                id,
                model.Name);

            // Not Found error
            if (!result)
            {
                this.ShowError(string.Format(ContestNotFoundError, id));
                return(this.All());
            }

            return(this.RedirectToContests());
        }
Esempio n. 11
0
        public ActionResult StartContest(int id)
        {
            ContestModel cm = new ContestModel();

            cm.ListQuiz = tn.ch_db.Where(x => x.MaDe == id).ToList();
            cm.Time     = tn.DeThis.Where(x => x.MaDe == id).Select(u => u.Time).FirstOrDefault();
            return(View(cm));
        }
Esempio n. 12
0
        public void SetContest(ContestModel cont)
        {
            var sp = TimeSpan.Parse(cont.scoreboard_freeze_duration);

            Contest         = cont;
            BoardFreezeTime = cont.end_time - sp;
            FreezeLength    = (int)sp.TotalMinutes;
        }
Esempio n. 13
0
 public ActionResult <ContestModel> PostContest(ContestModel contest)
 {
     if (contests.CreateNewContest(contest))
     {
         return(contest);
     }
     return(BadRequest());
 }
Esempio n. 14
0
        public ActionResult InsertContest(ContestModel CM, int id, string UserName)
        {
            CM.ContestWriterID = id;
            DBController dbController = new DBController();

            dbController.InsertContest(CM);
            return(RedirectToAction("ViewContests", new { id, UserName }));
        }
        public ActionResult InsertContest(ContestModel CM)
        {
            CM.ContestWriterID = Convert.ToInt16(Session["ID"]);
            DBController dbController = new DBController();

            dbController.InsertContest(CM);

            return(RedirectToAction("ViewContests"));
        }
        public ActionResult Submit([FromBody] ContestModel contestModel)
        {
            SerialNumber serialNumber = serialNumberRepository.Get(contestModel.SerialNumber);

            if (serialNumber == null)
            {
                return(BadRequest("Bad serial number"));
            }

            ContestParticipant participant = contestParticipantRepository.Get(contestModel.Email, contestModel.FirstName, contestModel.LastName);

            if (participant == null && serialNumber.ContestParticipantId != null)
            {
                return(BadRequest("Bad serial number"));
            }
            if (participant == null)
            {
                participant = new ContestParticipant {
                    Email     = contestModel.Email,
                    FirstName = contestModel.FirstName,
                    LastName  = contestModel.LastName
                };
                contestParticipantRepository.Create(participant);
            }

            if (serialNumber.ContestParticipantId == null)
            {
                serialNumber.ContestParticipantId = participant.Id;
                serialNumber.Redeemed             = 1;
                serialNumberRepository.Update(serialNumber);
            }
            else
            {
                bool found = false;
                foreach (SerialNumber sn in participant.SerialNumbers)
                {
                    if (sn.Number != contestModel.SerialNumber)
                    {
                        continue;
                    }
                    if (sn.Redeemed >= 2)
                    {
                        return(BadRequest("Serial number is already redemed 2 times"));
                    }
                    found = true;
                    sn.Redeemed++;
                    contestParticipantRepository.Update(participant);
                }
                if (!found)
                {
                    return(BadRequest("Bad serial number"));
                }
            }

            return(new OkResult());
        }
Esempio n. 17
0
        public ActionResult <ContestModel> GetContest(int id)
        {
            ContestModel contest = contests.Get1Contest(id);

            if (contest != null)
            {
                return(contest);
            }
            return(NotFound());
        }
Esempio n. 18
0
 public bool CreateNewContest(ContestModel contest)
 {
     db.contests.Add(contest);
     db.SaveChanges();
     if (db.contests.Contains(contest))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 19
0
        public IActionResult Edit(int id, ContestModel model)
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.Redirect("/"));
            }

            this.contests.Update(id, model, this.Profile);

            return(this.Redirect("/users/contests"));
        }
Esempio n. 20
0
        public async Task <IActionResult> Create([Bind("Id,Name,StartDate,Duration,Active")] ContestModel contestModel)
        {
            if (ModelState.IsValid)
            {
                contestModel.ApplicationUserId = _userManager.GetUserId(User);
                _context.Add(contestModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contestModel));
        }
        public void ContestController_Submit_WhenGiven_Max_Redeemed()
        {
            ContestModel cm = new ContestModel()
            {
                Email        = "*****@*****.**",
                FirstName    = "First",
                LastName     = "Last",
                SerialNumber = "maxReemed"
            };
            var result = controller.Submit(cm) as BadRequestObjectResult;

            Assert.Equal(400, result.StatusCode);
        }
        public void ContestController_Submit_WhenGivenInValid_SerialNumber()
        {
            ContestModel cm = new ContestModel()
            {
                Email        = "*****@*****.**",
                FirstName    = "First",
                LastName     = "Last",
                SerialNumber = "wrong"
            };
            var result = controller.Submit(cm) as BadRequestObjectResult;

            Assert.Equal(400, result.StatusCode);
        }
        public void ContestController_Submit_WhenGivenValidData()
        {
            ContestModel cm = new ContestModel()
            {
                Email        = "*****@*****.**",
                FirstName    = "First",
                LastName     = "Last",
                SerialNumber = "notRedeemed"
            };
            var result = controller.Submit(cm) as OkResult;

            Assert.Equal(200, result.StatusCode);
        }
Esempio n. 24
0
        public bool CreateNewJudgeParticipant(ContestModel contest, JudgeModel judge)
        {
            JudgeParticipantModel entry = new JudgeParticipantModel();

            entry.Contest = contest; //Foreign key
            entry.Judge   = judge;   //Foreign key
            db.judgeParticipant.Add(entry);
            db.SaveChanges();
            if (db.judgeParticipant.Contains(entry))
            {
                return(true);
            }
            return(false);
        }
        public void Create(ContestModel model, User creator)
        {
            using (var db = new JudgeAppContext())
            {
                var contest = new Contest()
                {
                    Name     = model.Name,
                    UserId   = creator.Id,
                    IsActive = true,
                };

                db.Contests.Add(contest);
                db.SaveChanges();
            }
        }
        public void Delete(int id, ContestModel model, User currentUser)
        {
            using (var db = new JudgeAppContext())
            {
                var contest = db.Contests.First(p => p.Id == id);

                if (!currentUser.IsAdmin && contest.UserId != currentUser.Id)
                {
                    return;
                }

                contest.IsActive = false;
                db.SaveChanges();
            }
        }
Esempio n. 27
0
        public IActionResult Edit(int id, ContestModel model)
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.RedirectToLogin());
            }

            if (!this.ValidateModel(model))
            {
                return(this.View());
            }

            this.contestService.Edit(id, model.Name);

            return(this.RedirectToAll());
        }
Esempio n. 28
0
        public int InsertContest(ContestModel CM)
        {
            string StoredProcedureName = StoredProcedures.InsertContest;

            Dictionary <string, object> Parameters = new Dictionary <string, object>();

            CM.ContestID = Count_Contests() + 1;;
            Parameters.Add("@ContestID", CM.ContestID);
            Parameters.Add("@ContestName", CM.ContestName);
            Parameters.Add("@ContestDate", DateTime.Now.Date);
            Parameters.Add("@ContestLength", CM.ContestLength);
            Parameters.Add("@ContestWriterID", CM.ContestWriterID);

            int contest = dbMan.ExecuteNonQuery(StoredProcedureName, Parameters);
            int problem = InsertProblem(CM);

            return(problem);
        }
Esempio n. 29
0
        private bool ValidateModel(ContestModel model)
        {
            if (string.IsNullOrEmpty(model.Name) || model.Name.Length < 3 || model.Name.Length > 100)
            {
                this.ShowError(ErrorConstants.ContestLengthError);
                this.SetViewModelData(model);

                return(false);
            }

            if (!char.IsUpper(model.Name.First()))
            {
                this.ShowError(ErrorConstants.ContestFirstLetterError);
                this.SetViewModelData(model);

                return(false);
            }

            return(true);
        }
        public IActionResult Create(ContestModel model)
        {
            // Authenticate users
            if (!this.User.IsAuthenticated)
            {
                return(this.RedirectToLogin());
            }

            // Validate model
            if (!this.IsValidModel(model))
            {
                this.ShowError(ContestError);
                return(this.View());
            }

            // Create contest in db
            this.contestService.Create(model.Name, this.Profile.Id);

            return(this.RedirectToContests());
        }