public ActionResult AddCrew(int personId, int showId, string position) { var entity = new ShowCrew(DatabaseSession.Load <Person>(personId), DatabaseSession.Load <Show>(showId), position); DatabaseSession.Save(entity); return(new ViewModelResult(new HttpApiResult { RedirectToURL = this.GetURL(c => c.PersonDetails(personId)), })); }
private static void ImportCrew() { var crew = oldDatabaseConnection.Query("SELECT * FROM crew").ToList(); var jobs = oldDatabaseConnection.Query("SELECT * FROM jobs").Select(x => { if (x.ID == null || string.IsNullOrWhiteSpace(x.job)) { return(null); } int order = 999; if (x.priority != null) { order = x.priority; } return(new { id = (int)x.ID, name = (string)x.job, order = order, }); }).Where(x => x != null).ToDictionary(x => x.id); Log("Importing " + crew.Count + " crew"); using (var session = sessionFactory.OpenSession()) { session.Transaction.Begin(); session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].ShowCrew ON;").ExecuteUpdate(); var maxId = 0; foreach (var _row in crew) { if (_row.peepID == null || _row.showID == null) { // broken? continue; } var entity = new ShowCrew(); entity.ShowCrewId = _row.ID; entity.Person = session.Load <Person>(_row.peepID); entity.Show = session.Load <Show>(_row.showID); int jobId = _row.jobID; entity.DisplayOrder = jobs[jobId].order; entity.Position = jobs[jobId].name; if (string.IsNullOrWhiteSpace(entity.Position)) { continue; // skip } 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.ShowCrewId); if (entity.ShowCrewId > maxId) { maxId = entity.ShowCrewId; } } session.Flush(); session.CreateSQLQuery("SET IDENTITY_INSERT [dbo].ShowCrew OFF;").ExecuteUpdate(); session.CreateSQLQuery("DBCC CHECKIDENT ('dbo.ShowCrew', RESEED, " + (maxId + 1) + ")").ExecuteUpdate(); session.Transaction.Commit(); session.Close(); } }
public ActionResult AddCrew(int personId, int showId, string position) { var entity = new ShowCrew(DatabaseSession.Load<Person>(personId), DatabaseSession.Load<Show>(showId), position); DatabaseSession.Save(entity); return new ViewModelResult(new HttpApiResult { RedirectToURL = this.GetURL(c => c.PersonDetails(personId)), }); }