public static void DeleteDirector(int id) { using (IMDbContext db = new IMDbContext()) { var result = db.Director.Find(id); result.IsDeleted = true; db.SaveChanges(); } }
public static void UpdateDirector(int id, string name) { using (IMDbContext db = new IMDbContext()) { var result = db.Director.Find(id); result.DirectorName = name; db.SaveChanges(); } }
public static void AddDirector(Director director) { using (IMDbContext db = new IMDbContext()) { if (db.Director.SingleOrDefault(d => d.DirectorName == director.DirectorName) == null) { db.Director.Add(director); db.SaveChanges(); } } }
public static void AddGenre(Genre genre) { using (IMDbContext db = new IMDbContext()) { var result = db.Genre.FirstOrDefault(g => g.GenreName == genre.GenreName); if (result == null) { db.Genre.Add(genre); db.SaveChanges(); } } }
public static void UpdateMovieScore(Movie movie) { using (IMDbContext db = new IMDbContext()) { var uptadedMovie = db.Movie.Find(movie.MovieID); uptadedMovie.Score = movie.Score; uptadedMovie.totalScore = movie.totalScore; uptadedMovie.ScoreCounter = movie.ScoreCounter; db.SaveChanges(); } }
public static void AddMovie(ViewMovie vm) { using (IMDbContext db = new IMDbContext()) { Movie newMovie = new Movie() { MovieName = vm.MovieName, Description = vm.Description, ReleaseDate = vm.ReleaseDate, Score = vm.Score, ScoreCounter = vm.ScoreCounter, totalScore = vm.TotalScore, GenreID = db.Genre.FirstOrDefault(g => g.GenreName == vm.GenreName).GenreID, DirectorID = db.Director.FirstOrDefault(d => d.DirectorName == vm.DirectorName).DirectorID }; db.Movie.Add(newMovie); db.SaveChanges(); } }
public static void UpdateMovie(ViewMovie vm) { using (IMDbContext db = new IMDbContext()) { var uptadedMovie = db.Movie.Find(vm.MovieID); uptadedMovie.MovieName = vm.MovieName; uptadedMovie.DirectorID = db.Director.FirstOrDefault(d => d.DirectorName == vm.DirectorName).DirectorID; uptadedMovie.GenreID = db.Genre.FirstOrDefault(g => g.GenreName == vm.GenreName).GenreID; uptadedMovie.Description = vm.Description; uptadedMovie.ReleaseDate = vm.ReleaseDate; uptadedMovie.Score = vm.Score; uptadedMovie.totalScore = vm.TotalScore; uptadedMovie.ScoreCounter = vm.ScoreCounter; db.SaveChanges(); } }
public bool Commit() { return(_context.SaveChanges() > 0); }
private static void RegisterActorToMovie() { { bool shouldAbort = false; do { Clear(); WriteLine("Skådespelare (personnr):"); string socialSecurityNumber = ReadLine(); WriteLine(); Actor actor = Context.Actor.FirstOrDefault(x => x.SocialSecurityNumber == socialSecurityNumber); WriteLine("Film (titel):"); string title = ReadLine(); Movie movie = Context.Movie.FirstOrDefault(x => x.Title == title); WriteLine(); WriteLine("Är detta korrekt? (J)a eller (N)ej"); bool hasInvalidInput = true; do { ConsoleKeyInfo keyPressed = ReadKey(true); switch (keyPressed.Key) { case ConsoleKey.J: hasInvalidInput = false; shouldAbort = true; Clear(); List <ActorMovie> actorMovies = Context.ActorMovie.ToList(); if (actorMovies != null) { if (actor == null) { WriteLine("Skådespelare finns ej"); Thread.Sleep(3000); } else if (movie == null) { WriteLine("Film finns ej"); Thread.Sleep(3000); } else { ActorMovie actorMovie = new ActorMovie(actor, movie); Context.ActorMovie.Add(actorMovie); Context.SaveChanges(); WriteLine("Skådespelare tillagd till film"); Thread.Sleep(3000); } } break; case ConsoleKey.N: hasInvalidInput = false; break; } } while (hasInvalidInput); } while (shouldAbort == false); } }
public static int? Upload(IMInstance iMInstance, string engNum, string fileNameWithLocalPath, string iMFolderPath) { if (!File.Exists(fileNameWithLocalPath)) return null; var projectIdForEngNum = GetWsId(iMInstance, new List<string> { engNum }); if (projectIdForEngNum.Count == 0) return null; var iMSession = new IMSession(iMInstance); var wsId = IM.Wrapper.Utility.IMUtility.GetWsObjectID(iMInstance, iMSession, IMWSObjectType.Workspace, (double)projectIdForEngNum[0].EngId); IManWorkspace imWs = iMInstance.UseAdmin.GetValueOrDefault(false) ? (IManWorkspace)iMSession.AdminSession().DMS.GetObjectByID(wsId) : (IManWorkspace)iMSession.UserSession().DMS.GetObjectByID(wsId); if (iMFolderPath.StartsWith("/") || iMFolderPath.StartsWith("\\")) { iMFolderPath = iMFolderPath.Substring(1); } IManDocumentFolder imFldr = GetIMDocFolder(imWs, iMFolderPath); if (imFldr == null) return null; IManDocument imDoc = imFldr.Database.CreateDocument(); imDoc.SetAttributeByID(imProfileAttributeID.imProfileDescription, Path.GetFileName(fileNameWithLocalPath)); imDoc.SetAttributeByID(imProfileAttributeID.imProfileType, GetIMDocType(imWs, Convert.ToString(imDoc.GetAttributeValueByID(imProfileAttributeID.imProfileDescription)))); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imWs.Owner.Name); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imWs.Owner.Name); imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, iMInstance.UserId); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileLastUser, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileClass, IMConst.CONST_IMPROFILECLASS); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom7, IMConst.CONST_IMPROFILECUSTOM7); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom1, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom1).ToString()); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom2, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom2).ToString()); var engFunction = imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom3).ToString(); if (!string.IsNullOrWhiteSpace(engFunction)) { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, engFunction); } else { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, IMConst.CONST_IMPROFILECUSTOM3); } foreach (IManAdditionalProperty imAddProp in imFldr.AdditionalProperties) { if (imAddProp == null) continue; int attID = Convert.ToInt32(imAddProp.Name.Substring(imAddProp.Name.LastIndexOf('_') + 1)); imProfileAttributeID imProfAttr = (imProfileAttributeID)attID; if (imProfAttr != imProfileAttributeID.imProfileAuthor && imProfAttr != imProfileAttributeID.imProfileAuthorDescription && imProfAttr != imProfileAttributeID.imProfileOperator && imProfAttr != imProfileAttributeID.imProfileOperatorDescription && imProfAttr != imProfileAttributeID.imProfileLastUser && imProfAttr != imProfileAttributeID.imProfileLastUserDescription) { } else { continue; } if (imAddProp.Value != IMConst.CONST_WORKSPACE_VALUE) { //Date if (imProfAttr == imProfileAttributeID.imProfileCustom21 || imProfAttr == imProfileAttributeID.imProfileCustom22 || imProfAttr == imProfileAttributeID.imProfileCustom23 || imProfAttr == imProfileAttributeID.imProfileCustom24) { DateTime parsedTime; if (DateTime.TryParse(imAddProp.Value, out parsedTime)) { imDoc.SetAttributeByID(imProfAttr, parsedTime); } else { imDoc.SetAttributeByID(imProfAttr, null); } } //Boolean else if (imProfAttr == imProfileAttributeID.imProfileCustom25 || imProfAttr == imProfileAttributeID.imProfileCustom26 || imProfAttr == imProfileAttributeID.imProfileCustom27 || imProfAttr == imProfileAttributeID.imProfileCustom28) { if (imAddProp.Value != null && imAddProp.Value.ToLower() == "true") { imDoc.SetAttributeByID(imProfAttr, true); } else { imDoc.SetAttributeByID(imProfAttr, false); } } else { imDoc.SetAttributeByID(imProfAttr, imAddProp.Value); } } else { imDoc.SetAttributeByID(imProfAttr, imFldr.Workspace.Profile.GetAttributeValueByID(imProfAttr)); } } IManCheckinResult checkInResult = imDoc.CheckInWithResults(fileNameWithLocalPath, imCheckinDisposition.imCheckinNewDocument, imCheckinOptions.imDontKeepCheckedOut); if (checkInResult.Succeeded) { AddSecurityToDoc(imDoc, imFldr); IManDocuments imDocs = (IManDocuments)imFldr.Contents; if (null != imDocs) { imDocs.AddDocumentReference(checkInResult.Result); } if (iMInstance.UseAdmin.GetValueOrDefault(false)) { using (var db = new IMDbContext(iMInstance)) { var original = db.DOCMASTER.Find(imDoc.Number, 1); //original.OPERATOR = iMInstance.UserId; //original.AUTHOR = iMInstance.UserId; original.LASTUSER = iMInstance.UserId; db.SaveChanges(); } } return imDoc.Number; } else { return null; } }
private static void AddActorToMovie() { Clear(); bool customerExists = false; bool incorrectKey = true; bool shouldNotExit = true; do { WriteLine("Skådespelare (personnummer): "); string socialSecurityNumber = ReadLine(); WriteLine("Filmtitel: "); string movieTitle = ReadLine(); WriteLine("Är detta korrekt? (J)a eller (N)ej"); ConsoleKeyInfo consoleKeyInfo; do { consoleKeyInfo = ReadKey(true); incorrectKey = !(consoleKeyInfo.Key == ConsoleKey.J || consoleKeyInfo.Key == ConsoleKey.N); } while (incorrectKey); if (consoleKeyInfo.Key == ConsoleKey.J) { var actor = context.Actor.FirstOrDefault(a => a.SocialSecurityNumber == socialSecurityNumber); var movie = context.Movie.FirstOrDefault(m => m.Title == movieTitle); if (actor != null) { MovieActor movieActor = new MovieActor(actor); movie.Actors.Add(movieActor); context.SaveChanges(); shouldNotExit = false; Clear(); WriteLine("Skådespelare registrerad på film"); Thread.Sleep(1000); } else if (actor == null) { shouldNotExit = false; Clear(); WriteLine("Skådespelare ej registrerad"); Thread.Sleep(1000); } } Clear(); } while (shouldNotExit); }
public static int?Upload(IMInstance iMInstance, string engNum, string fileNameWithLocalPath, string iMFolderPath) { if (!File.Exists(fileNameWithLocalPath)) { return(null); } var projectIdForEngNum = GetWsId(iMInstance, new List <string> { engNum }); if (projectIdForEngNum.Count == 0) { return(null); } var iMSession = new IMSession(iMInstance); var wsId = IM.Wrapper.Utility.IMUtility.GetWsObjectID(iMInstance, iMSession, IMWSObjectType.Workspace, (double)projectIdForEngNum[0].EngId); IManWorkspace imWs = iMInstance.UseAdmin.GetValueOrDefault(false) ? (IManWorkspace)iMSession.AdminSession().DMS.GetObjectByID(wsId) : (IManWorkspace)iMSession.UserSession().DMS.GetObjectByID(wsId); if (iMFolderPath.StartsWith("/") || iMFolderPath.StartsWith("\\")) { iMFolderPath = iMFolderPath.Substring(1); } IManDocumentFolder imFldr = GetIMDocFolder(imWs, iMFolderPath); if (imFldr == null) { return(null); } IManDocument imDoc = imFldr.Database.CreateDocument(); imDoc.SetAttributeByID(imProfileAttributeID.imProfileDescription, Path.GetFileName(fileNameWithLocalPath)); imDoc.SetAttributeByID(imProfileAttributeID.imProfileType, GetIMDocType(imWs, Convert.ToString(imDoc.GetAttributeValueByID(imProfileAttributeID.imProfileDescription)))); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imWs.Owner.Name); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imWs.Owner.Name); imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, iMInstance.UserId); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileLastUser, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileClass, IMConst.CONST_IMPROFILECLASS); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom7, IMConst.CONST_IMPROFILECUSTOM7); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom1, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom1).ToString()); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom2, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom2).ToString()); var engFunction = imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom3).ToString(); if (!string.IsNullOrWhiteSpace(engFunction)) { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, engFunction); } else { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, IMConst.CONST_IMPROFILECUSTOM3); } foreach (IManAdditionalProperty imAddProp in imFldr.AdditionalProperties) { if (imAddProp == null) { continue; } int attID = Convert.ToInt32(imAddProp.Name.Substring(imAddProp.Name.LastIndexOf('_') + 1)); imProfileAttributeID imProfAttr = (imProfileAttributeID)attID; if (imProfAttr != imProfileAttributeID.imProfileAuthor && imProfAttr != imProfileAttributeID.imProfileAuthorDescription && imProfAttr != imProfileAttributeID.imProfileOperator && imProfAttr != imProfileAttributeID.imProfileOperatorDescription && imProfAttr != imProfileAttributeID.imProfileLastUser && imProfAttr != imProfileAttributeID.imProfileLastUserDescription) { } else { continue; } if (imAddProp.Value != IMConst.CONST_WORKSPACE_VALUE) { //Date if (imProfAttr == imProfileAttributeID.imProfileCustom21 || imProfAttr == imProfileAttributeID.imProfileCustom22 || imProfAttr == imProfileAttributeID.imProfileCustom23 || imProfAttr == imProfileAttributeID.imProfileCustom24) { DateTime parsedTime; if (DateTime.TryParse(imAddProp.Value, out parsedTime)) { imDoc.SetAttributeByID(imProfAttr, parsedTime); } else { imDoc.SetAttributeByID(imProfAttr, null); } } //Boolean else if (imProfAttr == imProfileAttributeID.imProfileCustom25 || imProfAttr == imProfileAttributeID.imProfileCustom26 || imProfAttr == imProfileAttributeID.imProfileCustom27 || imProfAttr == imProfileAttributeID.imProfileCustom28) { if (imAddProp.Value != null && imAddProp.Value.ToLower() == "true") { imDoc.SetAttributeByID(imProfAttr, true); } else { imDoc.SetAttributeByID(imProfAttr, false); } } else { imDoc.SetAttributeByID(imProfAttr, imAddProp.Value); } } else { imDoc.SetAttributeByID(imProfAttr, imFldr.Workspace.Profile.GetAttributeValueByID(imProfAttr)); } } IManCheckinResult checkInResult = imDoc.CheckInWithResults(fileNameWithLocalPath, imCheckinDisposition.imCheckinNewDocument, imCheckinOptions.imDontKeepCheckedOut); if (checkInResult.Succeeded) { AddSecurityToDoc(imDoc, imFldr); IManDocuments imDocs = (IManDocuments)imFldr.Contents; if (null != imDocs) { imDocs.AddDocumentReference(checkInResult.Result); } if (iMInstance.UseAdmin.GetValueOrDefault(false)) { using (var db = new IMDbContext(iMInstance)) { var original = db.DOCMASTER.Find(imDoc.Number, 1); //original.OPERATOR = iMInstance.UserId; //original.AUTHOR = iMInstance.UserId; original.LASTUSER = iMInstance.UserId; db.SaveChanges(); } } return(imDoc.Number); } else { return(null); } }