コード例 #1
0
 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();
             }
         }
     }
 }
コード例 #2
0
        public UResult CheckUser(string login, string password)
        {
            using (var db = new FilmFinderDb())
            {
                GetHeshMd5 getHesh   = new GetHeshMd5();
                User       checkUser = new User();
                try
                {
                    checkUser = db.Users.First(i => i.Name == login);
                }
                catch (Exception e)
                {
                    db.Dispose();
                    return(UResult.UserFailed);
                }

                if (checkUser == null)
                {
                    return(UResult.UserFailed);
                }
                else
                {
                    if (checkUser.Password == getHesh.GetHesh(password))
                    {
                        SetCurrentUser(checkUser);
                        return(UResult.Access);
                    }
                    else
                    {
                        return(UResult.PasswordFailed);
                    }
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public AllSpecificAddingFilm GetSpecific()
        {
            AllSpecificAddingFilm tmp = new AllSpecificAddingFilm();

            using (var db = new FilmFinderDb())
            {
                var tmpActors = db.Actors.ToArray();
                tmp.Actors = new string[tmpActors.Length];
                for (int i = 0; i < tmpActors.Length; i++)
                {
                    tmp.Actors[i] = tmpActors[i].Name;
                }

                var tmpGener = db.Genres.ToArray();
                tmp.Geners = new string[tmpGener.Length];
                for (int i = 0; i < tmpGener.Length; i++)
                {
                    tmp.Geners[i] = tmpGener[i].Genr;
                }

                var tmpProdusser = db.Producers.ToArray();
                tmp.Produsers = new string[tmpProdusser.Length];
                for (int i = 0; i < tmpProdusser.Length; i++)
                {
                    tmp.Produsers[i] = tmpProdusser[i].Name;
                }
            }

            return(tmp);
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
 public int GetCountComments(string filmName)
 {
     using (var db = new FilmFinderDb())
     {
         return(db.Coments.Where(i => i.Film.Name == filmName).ToArray().Length);
     }
 }
コード例 #7
0
        public void CreateActorsObject(FilmFinderDb db)
        {
            for (int i = 0; i < FilmContent.Actors.Length; i++)
            {
                var actorToFilm = new ActorToFilm();
                actorToFilm.Film = _film;
                Actor[] tmp = db.Actors.ToList().Where(j => j.Name == FilmContent.Actors[i]).ToArray();



                if (tmp.Length == 0)
                {
                    Actor actor = new Actor()
                    {
                        Name = FilmContent.Actors[i]
                    };
                    db.Actors.Add(actor);
                    actorToFilm.Actor = actor;
                    db.ActorToFilms.Add(actorToFilm);
                    continue;
                }
                actorToFilm.Actor = tmp[0];
                db.ActorToFilms.Add(actorToFilm);
            }
        }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
        public int GetFavoritFilmsCount()
        {
            int count = 0;

            using (var db = new FilmFinderDb())
            {
                count = db.FavoritLists.Count(i => i.User.Name == _currentUser.Login);
            }

            return(count);
        }
コード例 #10
0
        public int GetFilmsCount()
        {
            int count;

            using (var db = new FilmFinderDb())
            {
                count = db.Films.Count();
            }

            return(count);
        }
コード例 #11
0
        public FilmContent GetFavoritFilms(int index)
        {
            FilmContent newFilm = new FilmContent();

            using (var db = new FilmFinderDb())
            {
                var favoritList = db.FavoritLists.ToArray().Where(i => i.User.Name == _currentUser.Login);
                var film        = favoritList.ToArray()[index].Film;
                newFilm.Name        = film.Name;
                newFilm.Description = film.Description;


                newFilm.ReleaseDate = film.ReleaseDate;

                var actors = db.ActorToFilms.ToArray().Where(i => i.Film == film).ToArray();
                newFilm.Actors = new string[actors.Length];

                for (int i = 0; i < actors.Length; i++)
                {
                    newFilm.Actors[i] = actors[i].Actor.Name;
                }

                newFilm.IsFavorit = db.FavoritLists.ToList().Any(i => i.Film.Name == film.Name && i.User.Name == _currentUser.Login);
                //newFilm.Image = File.ReadAllBytes(film.Image);
                newFilm.FilmTime = film.TimeFilm;

                /////////////////
                Bitmap btm = new Bitmap(film.Image);
                using (MemoryStream ms = new MemoryStream())
                {
                    btm.Save(ms, ImageFormat.Jpeg);
                    btm.Dispose();
                    newFilm.Image = ms.GetBuffer();
                }

                ///////////////

                var produssers = db.ProdusserToFilms.ToArray().Where(i => i.Film == film).ToArray();
                newFilm.Produsers = new string[produssers.Length];
                for (int i = 0; i < produssers.Length; i++)
                {
                    newFilm.Produsers[i] = produssers[i].Producer.Name;
                }

                var genrs = db.GenreToFilms.ToArray().Where(i => i.Film == film).ToArray();
                newFilm.Geners = new string[genrs.Length];
                for (int i = 0; i < genrs.Length; i++)
                {
                    newFilm.Geners[i] = genrs[i].Genre.Genr;
                }
            }

            return(newFilm);
        }
コード例 #12
0
 public void Create()
 {
     CreateFolderToImageFilm();
     using (var db = new FilmFinderDb())
     {
         db.Films.Add(_film);
         CreateActorsObject(db);
         CreateGenersObject(db);
         CreateProdussersObject(db);
         db.SaveChanges();
     }
 }
コード例 #13
0
 public MessageData GetComments(int index, string filmName)
 {
     using (var db = new FilmFinderDb())
     {
         var         comment = db.Coments.Where(i => i.Film.Name == filmName).ToArray()[index];
         MessageData msg     = new MessageData();
         msg.NickName = new CurrentUser()
         {
             Login = comment.User.Name, DateBirthday = comment.User.DateBirthday, UserImage = comment.User.UserImage
         };
         msg.Message = comment.Сommentary;
         return(msg);
     }
 }
コード例 #14
0
 public int GetCurrentRaiting(string nameOfFilm)
 {
     using (var db = new FilmFinderDb())
     {
         if (db.Marks.Any(i => i.Film.Name == nameOfFilm && i.User.Name == _currentUser.Login))
         {
             return(db.Marks.First(i => i.Film.Name == nameOfFilm && i.User.Name == _currentUser.Login).Marks);
         }
         else
         {
             return(0);
         }
     }
 }
コード例 #15
0
        public int AddNewFilm(FilmContent content)
        {
            using (var db = new FilmFinderDb())
            {
                if (db.Films.Any(i => i.Name == content.Name))
                {
                    return((int)UResult.FilmFailed);
                }
            }
            CreateNewFilm createNewFilm = new CreateNewFilm(content, _currentUser);

            createNewFilm.Create();
            return((int)UResult.Access);
        }
コード例 #16
0
 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();
     }
 }
コード例 #17
0
        public Film CreateFilmObject()
        {
            Film newFilm;

            using (var db = new FilmFinderDb())
            {
                newFilm = new Film()
                {
                    Name        = FilmContent.Name,
                    Description = FilmContent.Description,
                    ReleaseDate = FilmContent.ReleaseDate,
                    User        = db.Users.ToList().First(i => i.Name == _currentUser.Login),
                    Image       = @"./Films_images/" + FilmContent.Name.Replace(" ", "_") + "/" +
                                  FilmContent.ImageName.Replace(" ", "_")
                };
                newFilm.TimeFilm = FilmContent.FilmTime;
            }

            return(newFilm);
        }
コード例 #18
0
        public float GetRaitingOfFilm(string nameOfFilm)
        {
            float middleRaiting = 0;

            using (var db = new FilmFinderDb())
            {
                int counter = 0;
                foreach (var mark in db.Marks.ToList().Where(i => i.Film.Name == nameOfFilm))
                {
                    middleRaiting += mark.Marks;
                    counter++;
                }

                if (counter != 0)
                {
                    middleRaiting = middleRaiting / counter;
                }
            }

            return((float)Math.Round(middleRaiting, 2));
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
        public void CreateGenersObject(FilmFinderDb db)
        {
            for (int i = 0; i < FilmContent.Geners.Length; i++)
            {
                var genreToFilm = new GenreToFilm();
                genreToFilm.Film = _film;
                var tmp = db.Genres.ToList().Where(j => j.Genr == FilmContent.Geners[i]).ToList();
                if (tmp.Count == 0)
                {
                    Genre genre = new Genre()
                    {
                        Genr = FilmContent.Geners[i]
                    };
                    db.Genres.Add(genre);
                    genreToFilm.Genre = genre;
                    db.GenreToFilms.Add(genreToFilm);
                    continue;
                }

                genreToFilm.Genre = tmp[0];
                db.GenreToFilms.Add(genreToFilm);
            }
        }
コード例 #21
0
        public void CreateProdussersObject(FilmFinderDb db)
        {
            for (int i = 0; i < FilmContent.Produsers.Length; i++)
            {
                var produsserToFilm = new ProdusserToFilm();
                produsserToFilm.Film = _film;
                var tmp = db.Producers.ToList().Where(j => j.Name == FilmContent.Produsers[i]).ToList();
                if (tmp.Count == 0)
                {
                    Producer producer = new Producer()
                    {
                        Name = FilmContent.Produsers[i]
                    };
                    db.Producers.Add(producer);
                    produsserToFilm.Producer = producer;
                    db.ProdusserToFilms.Add(produsserToFilm);
                    continue;
                }

                produsserToFilm.Producer = tmp[0];
                db.ProdusserToFilms.Add(produsserToFilm);
            }
        }