/// <summary> /// Adds a movie to database taking into consideration all possible exceptions /// </summary> /// <param name="FileName">Name of the movie filename</param> public static void AddMovie(string FilePath) { //Adds a movie id, movie name and movie path to database try { string FileName = System.IO.Path.GetFileNameWithoutExtension(FilePath); MovieDatabaseEntities db = new MovieDatabaseEntities(); MainMovieList objMovie = new MainMovieList(); if (db.MainMovieLists.Any(o => o.File_Name == FileName)) { Console.WriteLine(FileName + " is already in the MainMovieList table"); } else { objMovie.File_Name = FileName; objMovie.File_Path = FilePath; db.MainMovieLists.Add(objMovie); db.SaveChanges(); } int usrId = MainApplicationWindow.getCurrentUserID(); Console.WriteLine("Current username: "******"\n"); if (db.Favourite_Hated.Any(o => o.FilmID == objMovie.ID && o.UserID == usrId)) { Console.WriteLine(FileName + " is already in the Favourite_Hated table"); } else { Console.WriteLine("Adding " + FileName + " to the Favourite_Hated table for user with id: " + usrId); User usr = new User(); var searchs = db.Users.SingleOrDefault(o => o.UserID == usrId); AddFavouriteOrHated(-1, searchs.Username, FileName); } //Jezeli nie dasz sobie rady ze stworzeniem query: stworz funckje foreach i sprawdz czy dany film ma konkretny usrname i filmid } catch (DbEntityValidationException e) { //In case of error while adding stuff to database foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
private void monoFlat_Button1_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; User user = new User(); MovieDatabaseEntities db = new MovieDatabaseEntities(); validation = true; loginError[i] = new MonoFlat.MonoFlat_NotificationBox(); loginError[i].BorderCurve = 8; loginError[i].Font = new System.Drawing.Font("Tahoma", 9F); loginError[i].Image = null; loginError[i].Location = new System.Drawing.Point(this.Width / 2 - 100, this.Height - 180); loginError[i].MinimumSize = new System.Drawing.Size(100, 40); loginError[i].Name = "monoFlat_NotificationBox1"; loginError[i].NotificationType = MonoFlat.MonoFlat_NotificationBox.Type.Error; loginError[i].RoundCorners = true; loginError[i].ShowCloseButton = false; loginError[i].Size = new System.Drawing.Size(200, 85); loginError[i].TabIndex = 6; loginError[i].MouseHover += new EventHandler(LoginError_MouseHover); if (monoFlat_TextBox2.Text == monoFlat_TextBox3.Text) { foreach (var username in db.Users) { if (username.Username==monoFlat_TextBox1.Text) { loginError[i].Text = "Username Error:\nThis user name is already occupied."; monoFlat_ThemeContainer1.Controls.Add(loginError[i]); loginError[i].BringToFront(); validation = false; monoFlat_TextBox1.Text = null; break; } if (monoFlat_TextBox1.Text.Length < 3) { loginError[i].Text = "Username Error:\nUsername must contatin at least 3 characters."; monoFlat_ThemeContainer1.Controls.Add(loginError[i]); loginError[i].BringToFront(); validation = false; monoFlat_TextBox1.Text = null; break; } if (monoFlat_TextBox2.Text.Length < 5) { loginError[i].Text = "Password Error:\nPassword must be of at least 5 characters."; monoFlat_ThemeContainer1.Controls.Add(loginError[i]); loginError[i].BringToFront(); validation = false; break; } } } else { loginError[i].Text = "Password Error:\nPasswords don't match!"; monoFlat_ThemeContainer1.Controls.Add(loginError[i]); loginError[i].BringToFront(); validation = false; } if (validation) { user.Username = monoFlat_TextBox1.Text; user.Password = monoFlat_TextBox2.Text; user.Number_Of_Playlists = 0; db.Users.Add(user); db.SaveChanges(); validation = false; var successPrompt = new MonoFlat.MonoFlat_NotificationBox(); successPrompt.BorderCurve = 8; successPrompt.Font = new System.Drawing.Font("Tahoma", 9F); successPrompt.Image = null; successPrompt.Location = new System.Drawing.Point(this.Width / 2 - 150, this.Height/2 -50); successPrompt.Name = "monoFlat_NotificationBox1"; successPrompt.NotificationType = MonoFlat.MonoFlat_NotificationBox.Type.Success; successPrompt.RoundCorners = true; successPrompt.ShowCloseButton = false; successPrompt.Size = new System.Drawing.Size(300, 105); successPrompt.Text = ("You have succesfully created your account " + monoFlat_TextBox1.Text + ".\nGo now and log in.\nThis window will shutdown in a moment"); monoFlat_ThemeContainer1.Controls.Add(successPrompt); successPrompt.BringToFront(); foreach (Control c in this.Controls) c.Enabled = false; System.Threading.Thread.Sleep(5000); this.Dispose(); } i++; Cursor.Current = Cursors.Default; }
/// <summary> /// removes playlist and button connected with it /// </summary> /// <param name="i">tg of removed button</param> /// <param name="usrID">id of current user</param> /// <param name="usr">Current user</param> private void Remove_Playlist(int i, int usrID, User usr) { MovieDatabaseEntities db = new MovieDatabaseEntities(); foreach (Playlist pl in db.Playlists) { if (pl.PlaylistID == i && pl.UserID == usrID) db.Playlists.Remove(pl); } foreach (List_Of_Playlists lop in db.List_Of_Playlists) { if (lop.ID == i && lop.UserID == usrID) { db.List_Of_Playlists.Remove(lop); usr.Number_Of_Playlists--; } } db.SaveChanges(); deletePlaylistButton((int)buttonToBeRemoved.Tag); //Playlists_Panel.Controls.Remove(buttonToBeRemoved); buttonToBeRemoved = null; foreach (MonoFlat_Button but in Playlists_Panel.Controls) { if ((int)but.Tag > i) { but.Location = new Point(but.Location.X - 95, but.Location.Y); } } }