public int CreateMovie(DbTorronto db, Movie movie) { int movieId = 0; movie.Created = DateTime.UtcNow; movie.Updated = DateTime.UtcNow; try { movieId = Convert.ToInt32( db.InsertWithIdentity(movie) ); } catch (Exception ex) { _logger.Warn("MovieService.CreateMovie", ex); } return(movieId); }
public User AddUser(string name, string email, string providerName, string providerId) { using (var db = new DbTorronto()) using (db.BeginTransaction()) { var user = new User { Identifier = Guid.NewGuid(), DisplayName = name, AuthProviderID = string.Empty, AuthProviderName = string.Empty, Password = "******", Email = email, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, FilterSizes = string.Empty }; user.ID = Convert.ToInt32( db.InsertWithIdentity(user) ); var identity = new UserIdentity { UserID = user.ID.GetValueOrDefault(), Email = email, AuthProviderID = providerId, AuthProviderName = providerName, DisplayName = name, Created = DateTime.UtcNow, }; db.Insert(identity); db.CommitTransaction(); return(user); } }
public void SaveDetails(Movie detailed) { using (var db = new DbTorronto()) { db.Movie .Where(x => x.ID == detailed.ID) .Set(f => f.IsDetailed, detailed.IsDetailed) .Set(f => f.Title, detailed.Title) .Set(f => f.OriginalTitle, detailed.OriginalTitle) .Set(f => f.ReleaseDate, detailed.ReleaseDate) .Set(f => f.Description, detailed.Description) .Set(f => f.ImdbID, detailed.ImdbID) .Set(f => f.DurationMinutes, detailed.DurationMinutes) .Update(); var actorPosition = 0; foreach (var actor in detailed.Persons) { var existingActor = db.Person.FirstOrDefault(p => p.SiteID == actor.SiteID); if (existingActor == null) { existingActor = new Person { Name = actor.Name, SiteID = actor.SiteID }; existingActor.ID = Convert.ToInt32( db.InsertWithIdentity(existingActor) ); } db.MoviePerson.InsertOrUpdate( () => new MoviePerson { MovieID = detailed.ID.GetValueOrDefault(), PersonID = existingActor.ID.GetValueOrDefault(), Position = actorPosition }, old => new MoviePerson { Position = actorPosition } ); actorPosition++; } var genrePosition = 0; foreach (var genre in detailed.Genres) { var existingGenre = db.Genre.FirstOrDefault(p => p.SiteID == genre.SiteID); if (existingGenre == null) { existingGenre = new Genre { Name = genre.Name, SiteID = genre.SiteID }; existingGenre.ID = Convert.ToInt32( db.InsertWithIdentity(existingGenre) ); } db.MovieGenre.InsertOrUpdate( () => new MovieGenre { MovieID = detailed.ID.GetValueOrDefault(), GenreID = existingGenre.ID.GetValueOrDefault(), Position = genrePosition }, old => new MovieGenre { Position = genrePosition } ); genrePosition++; } } }