public RaceModel(Race raceDb) { RaceId = raceDb.RaceID; if (raceDb.EventId.HasValue) { EventId = raceDb.EventId.Value; Event = EventModel.GetById(raceDb.EventId.Value); } Name = raceDb.Name; StartDate = raceDb.StartDate; Distance = raceDb.Distance; }
public void TestSetup() { ctxDBTest = new Entities(); newEvent = new EventModel("TestEvent", DateTime.Today); newEvent.Save(); newRace = new RaceModel("RaceModelTestRace", new DateTime(2009, 2, 3)); newRace.EventId = newEvent.EventId; newRace.Save(); raceDB = new Race(); raceDB.EventId = newEvent.EventId; raceDB.Name = "TestingRaceModel"; raceDB.Distance = 200; raceDB.StartDate = DateTime.Parse("10/03/2020"); ctxDBTest.Races.AddObject(raceDB); ctxDBTest.SaveChanges(); }
/// <summary> /// Deprecated Method for adding a new object to the Races EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRaces(Race race) { base.AddObject("Races", race); }
/// <summary> /// Create a new Race object. /// </summary> /// <param name="raceID">Initial value of the RaceID property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="startDate">Initial value of the StartDate property.</param> /// <param name="isDeleted">Initial value of the IsDeleted property.</param> public static Race CreateRace(global::System.Int32 raceID, global::System.String name, global::System.DateTime startDate, global::System.Boolean isDeleted) { Race race = new Race(); race.RaceID = raceID; race.Name = name; race.StartDate = startDate; race.IsDeleted = isDeleted; return race; }
private void CheckAndDeletelDuplicateRace(Race existingRace) { using (var ctxDel = new Entities()) { if (ctxDel.Races.Any(race => (race.Name == existingRace.Name && race.Distance == existingRace.Distance && race.StartDate == existingRace.StartDate))) { var DelRace = ctxDel.Races.Where(race => (race.Name == existingRace.Name && race.Distance == existingRace.Distance && race.StartDate == existingRace.StartDate)).Single(); ctxDel.DeleteObject(DelRace); ctxDel.SaveChanges(); } } }
public bool Save() { using (var context = new Entities()) { if (context.Races.Where(r => r.EventId == EventId).Any(r => r.Name == Name)) throw new ArgumentException("Det eksisterer allerede et løp med samme navn for dette stevnet"); var race = new Race(); race.Name = Name; race.StartDate = StartDate; race.Distance = Distance; race.EventId = EventId; context.Races.AddObject(race); try { context.SaveChanges(); this.RaceId = race.RaceID; return true; } catch (Exception) { return false; } } }