public static void AddNewCompetition(Models.CompetitionModel model) { Competition comp = new Competition(); comp.CategoryId = model.CategoryId; comp.Start = model.Start; comp.End = model.End; comp.Duration = model.Duration; comp.Name = model.Name; comp.Description = model.Description; using (TopCoderPrototypeEntities entityModel = new TopCoderPrototypeEntities()) { entityModel.AddToCompetitions(comp); entityModel.SaveChanges(); if (model.SelectedProblems != null) { foreach (var problem in model.SelectedProblems) { CompetetionsProblem cp = new CompetetionsProblem(); cp.CompetetionId = comp.ID; cp.ProblemId = problem; entityModel.CompetetionsProblems.AddObject(cp); } entityModel.SaveChanges(); } } }
/// <summary> /// Create a new CompetetionsProblem object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="competetionId">Initial value of the CompetetionId property.</param> /// <param name="problemId">Initial value of the ProblemId property.</param> public static CompetetionsProblem CreateCompetetionsProblem(global::System.Int32 id, global::System.Int32 competetionId, global::System.Int32 problemId) { CompetetionsProblem competetionsProblem = new CompetetionsProblem(); competetionsProblem.ID = id; competetionsProblem.CompetetionId = competetionId; competetionsProblem.ProblemId = problemId; return competetionsProblem; }
/// <summary> /// Deprecated Method for adding a new object to the CompetetionsProblems EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCompetetionsProblems(CompetetionsProblem competetionsProblem) { base.AddObject("CompetetionsProblems", competetionsProblem); }
internal static void EditCompetition(int id, CompetitionModel model) { using (TopCoderPrototypeEntities entityModel = new TopCoderPrototypeEntities()) { Competition comp = entityModel.Competitions.Where(x => x.ID == id).FirstOrDefault(); if (comp != null) { comp.CategoryId = model.CategoryId; comp.Start = model.Start; comp.End = model.End; comp.Duration = model.Duration; comp.Name = model.Name; comp.Description = model.Description; } entityModel.SaveChanges(); entityModel.CompetetionsProblems.Where(x => x.CompetetionId == id).ToList() .ForEach(entityModel.CompetetionsProblems.DeleteObject); if (model.SelectedProblems != null) { foreach (var problem in model.SelectedProblems) { CompetetionsProblem cp = new CompetetionsProblem(); cp.CompetetionId = comp.ID; cp.ProblemId = problem; entityModel.CompetetionsProblems.AddObject(cp); } } entityModel.SaveChanges(); } }