public void SetFavorit(string filmName, bool isFavorit) { using (var db = new FilmFinderDb()) { var film = db.Films.ToList().First(i => i.Name == filmName); if (isFavorit && !db.FavoritLists.Any(i => i.Film.Name == film.Name && i.User.Name == _currentUser.Login)) { FavoritList favoritList = new FavoritList(); favoritList.User = db.Users.ToList().First(i => i.Name == _currentUser.Login); favoritList.Film = film; db.FavoritLists.Add(favoritList); db.SaveChanges(); } else if (!isFavorit) { var isEnable = db.FavoritLists.Any(i => i.Film.Name == film.Name && i.User.Name == _currentUser.Login); if (isEnable) { var favoritFilms = db.FavoritLists.First(i => i.Film.Name == film.Name && i.User.Name == _currentUser.Login); db.FavoritLists.Remove(favoritFilms); db.SaveChanges(); } } } }
public int AddNewUserOnDB(RegistrateCurrentUser registrate) { using (var db = new FilmFinderDb()) { if (db.Users.Any(i => i.Name == registrate.Login)) { return((int)UResult.UserFailed); } bool tmpGender = true; switch (registrate.Gender) { case 0: tmpGender = false; break; case 1: tmpGender = true; break; } GetHeshMd5 getHesh = new GetHeshMd5(); db.Users.Add(new User() { DateBirthday = registrate.DateBirthday, Name = registrate.Login, Password = getHesh.GetHesh(registrate.Password), Gender = tmpGender, UserImage = File.ReadAllBytes("./usericon.png") }); db.SaveChanges(); } return((int)UResult.Access); }
public void ChangeUserProfile(RegistrateCurrentUser user) { using (var db = new FilmFinderDb()) { var usr = db.Users.First(i => i.Name == _currentUser.Login); if (user.Password != null) { usr.Password = new GetHeshMd5().GetHesh(user.Password); } bool tmpGender = true; switch (user.Gender) { case 0: tmpGender = false; break; case 1: tmpGender = true; break; } usr.Gender = tmpGender; usr.DateBirthday = usr.DateBirthday; db.SaveChanges(); } }
public void UploadUserImage(byte[] image) { using (var db = new FilmFinderDb()) { var user = db.Users.ToList().First(i => i.Name == _currentUser.Login); user.UserImage = image; _currentUser.UserImage = image; db.SaveChanges(); } }
public void SetRaiting(int raiting, string nameOfFilm) { using (var db = new FilmFinderDb()) { var tmpUser = db.Users.First(j => j.Name == _currentUser.Login); if (db.Marks.Any(i => i.Film.Name == nameOfFilm && i.User.Name == tmpUser.Name)) { var tmpMark = db.Marks.First(i => i.Film.Name == nameOfFilm && i.User.Name == tmpUser.Name); tmpMark.Marks = raiting; db.SaveChanges(); return; } Mark mark = new Mark(); mark.Film = db.Films.ToList().First(i => i.Name == nameOfFilm); mark.User = db.Users.ToList().First(i => i.Name == _currentUser.Login); mark.Marks = raiting; db.Marks.Add(mark); db.SaveChanges(); } }
public void Create() { CreateFolderToImageFilm(); using (var db = new FilmFinderDb()) { db.Films.Add(_film); CreateActorsObject(db); CreateGenersObject(db); CreateProdussersObject(db); db.SaveChanges(); } }
public void AddComment(string filmName, string comment) { using (var db = new FilmFinderDb()) { Coment coment = new Coment(); var user = db.Users.First(i => i.Name == _currentUser.Login); var film = db.Films.First(i => i.Name == filmName); coment.Film = film; coment.User = user; coment.Сommentary = comment; db.Coments.Add(coment); db.SaveChanges(); } }