public ActionResult NewContestIp(NewContestIpViewModel model) { if (!this.Data.Participants.Any(model.ContestId, this.UserProfile.Id, true)) { return(this.RedirectToAction("Register", new { id = model.ContestId, official = true })); } if (this.contestsBusiness.IsContestIpValidByContestAndIp(model.ContestId, this.Request.UserHostAddress)) { return(this.RedirectToAction(GlobalConstants.Index, new { id = model.ContestId, official = true })); } var contest = this.Data.Contests.All().Include(x => x.AllowedIps).Include("AllowedIps.Ip").FirstOrDefault(x => x.Id == model.ContestId); this.ValidateContest(contest, true); if (!string.Equals(contest.NewIpPassword, model.NewIpPassword, StringComparison.InvariantCulture)) { this.ModelState.AddModelError("NewIpPassword", "Невалидна парола."); return(this.View(model)); } var currentUserIpAddress = this.Request.UserHostAddress; if (contest.AllowedIps.All(y => y.Ip.Value != currentUserIpAddress)) { var ip = this.Data.Ips.All().FirstOrDefault(x => x.Value == currentUserIpAddress); if (ip == null) { ip = new Ip { Value = currentUserIpAddress }; this.Data.Ips.Add(ip); } contest.AllowedIps.Add(new ContestIp { Ip = ip, IsOriginallyAllowed = false }); this.Data.SaveChanges(); } return(this.RedirectToAction(GlobalConstants.Index, new { id = model.ContestId, official = true })); }
public ActionResult NewContestIp(NewContestIpViewModel model) { if (!this.participantsData.ExistsByContestByUserAndIsOfficial(model.ContestId, this.UserProfile.Id, true)) { return(this.RedirectToAction("Register", new { id = model.ContestId, official = true })); } if (this.contestsBusiness.IsContestIpValidByContestAndIp(model.ContestId, this.Request.UserHostAddress)) { return(this.RedirectToAction(GlobalConstants.Index, new { id = model.ContestId, official = true })); } var contest = this.contestsData .GetByIdQuery(model.ContestId) .Include(x => x.AllowedIps.Select(aIp => aIp.Ip)) .FirstOrDefault(); this.ValidateContest(contest, true); if (!string.Equals(contest.NewIpPassword, model.NewIpPassword, StringComparison.InvariantCulture)) { this.ModelState.AddModelError("NewIpPassword", "Невалидна парола."); return(this.View(model)); } var currentUserIpAddress = this.Request.UserHostAddress; if (contest.AllowedIps.All(y => y.Ip.Value != currentUserIpAddress)) { var ip = this.ipsData.GetByValue(currentUserIpAddress) ?? new Ip { Value = currentUserIpAddress }; contest.AllowedIps.Add(new ContestIp { Ip = ip, IsOriginallyAllowed = false }); this.contestsData.Update(contest); } return(this.RedirectToAction(GlobalConstants.Index, new { id = model.ContestId, official = true })); }
public ActionResult NewContestIp(int id) { if (!this.Data.Participants.Any(id, this.UserProfile.Id, true)) { return(this.RedirectToAction("Register", new { id, official = true })); } if (this.contestsBusiness.IsContestIpValidByContestAndIp(id, this.Request.UserHostAddress)) { return(this.RedirectToAction(GlobalConstants.Index, new { id, official = true })); } var contest = this.contestsData.GetById(id); this.ValidateContest(contest, true); var model = new NewContestIpViewModel { ContestId = id }; return(this.View(model)); }