private static void ImportEC() { var ec = oldDatabaseConnection.Query("SELECT * FROM ec").ToList(); var ec_list = oldDatabaseConnection.Query("SELECT * FROM ec_list").Select(x => { if (x.ID == null) { return(null); } return(new { id = (int)x.ID, name = (string)x.title ?? "", }); }).Where(x => x != null).ToDictionary(x => x.id); Log("Importing " + ec.Count + " ec"); using (var session = sessionFactory.OpenSession()) { session.Transaction.Begin(); session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].PersonClubPosition ON;").ExecuteUpdate(); var maxId = 0; foreach (var _row in ec) { if (_row.peepID == null) { // broken? continue; } var entity = new PersonClubPosition(); entity.PersonClubPositionId = _row.ID; entity.Person = session.Load <Person>(_row.peepID); entity.Position = ec_list[_row.ECID].name; entity.Year = (short)_row.year; if (string.IsNullOrWhiteSpace(entity.Position)) { continue; // skip } entity.DisplayOrder = _row.ECID; entity.InsertedDateTime = DateTime.MinValue; entity.LastModifiedDateTime = DateTime.MinValue; if (_row.last_mod != null) { entity.InsertedDateTime = TimeZoneInfo.ConvertTimeToUtc(_row.last_mod, TimeZoneCode.Eastern.ToTimeZoneInfo()); entity.LastModifiedDateTime = TimeZoneInfo.ConvertTimeToUtc(_row.last_mod, TimeZoneCode.Eastern.ToTimeZoneInfo()); } session.Save(entity, entity.PersonClubPositionId); if (entity.PersonClubPositionId > maxId) { maxId = entity.PersonClubPositionId; } } session.Flush(); session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].PersonClubPosition OFF;").ExecuteUpdate(); session.CreateSQLQuery("DBCC CHECKIDENT ('dbo.PersonClubPosition', RESEED, " + (maxId + 1) + ")").ExecuteUpdate(); session.Transaction.Commit(); session.Close(); } }
public ActionResult AddClubPosition(int personId, string position, short year) { var entity = new PersonClubPosition(DatabaseSession.Load <Person>(personId), position, year); DatabaseSession.Save(entity); return(new ViewModelResult(new HttpApiResult { RedirectToURL = this.GetURL(c => c.PersonDetails(personId)), })); }
public ActionResult AddClubPosition(int personId, string position, short year) { var entity = new PersonClubPosition(DatabaseSession.Load<Person>(personId), position, year); DatabaseSession.Save(entity); return new ViewModelResult(new HttpApiResult { RedirectToURL = this.GetURL(c => c.PersonDetails(personId)), }); }