public void SaveMonthlyLangComp(MonthlyLangStackCompetition m) { using (IDbConnection dbConnection = Connection) { string query = "INSERT INTO monthlyLangStackCompetitions (CompetitionId, MonthlyLangStackId) VALUES (@CompetitionId, @MonthlyLangStackId);"; dbConnection.Open(); dbConnection.Execute(query, m); } }
public IActionResult AddCompetition(string name, int type, int size, DateTime startdate, DateTime starttime, DateTime enddate, DateTime endtime, List <int> stacks) { if (CheckUser() && (int)HttpContext.Session.GetInt32("AccessLevel") == 9) { HttpContext.Session.SetObjectAsJson("compErrors", new Dictionary <string, string>()); //accept name, type, size, startdate, starttime, enddate, endtime DateTime start = startdate.Date.Add(starttime.TimeOfDay); DateTime end = enddate.Date.Add(endtime.TimeOfDay); Competition comp = new Competition { CompetitionName = name, CompetitionTypeId = type, MaxSize = size, Start = start, End = end, }; if (TryValidateModel(comp) && stacks.Count > 0) { int compId = _compFactory.SaveCompetition(comp); foreach (int s in stacks) { MonthlyLangStackCompetition m = new MonthlyLangStackCompetition { CompetitionId = compId, MonthlyLangStackId = s }; _compFactory.SaveMonthlyLangComp(m); } return(RedirectToAction("AdminNav", "Admin")); } else { List <string> errors = new List <string>(); foreach (var v in ModelState.Values) { if (v.Errors.Count > 0) { errors.Add(v.Errors[0].ErrorMessage); } } if (stacks.Count == 0) { errors.Add("At least one stack must be selected"); } HttpContext.Session.SetObjectAsJson("compErrors", errors); return(RedirectToAction("Competition", "Admin")); } } else { return(RedirectToAction("Index", "Home")); } }