Beispiel #1
0
        public string updateAccessToken(int userId, string accessToken)
        {
            string status = "";

            try
            {
                using (MovieEntities db = new MovieEntities())
                {
                    var query = db.UsersSessions.Where(x => x.Users_ID == userId).FirstOrDefault();
                    if (query != null)
                    {
                        query.token       = accessToken;
                        query.createdDate = DateTime.UtcNow;
                        db.SaveChanges();
                    }
                    else
                    {
                        var usersession = new UsersSession();
                        usersession.Users_ID    = userId;
                        usersession.token       = accessToken;
                        usersession.createdDate = DateTime.UtcNow;

                        db.UsersSessions.Add(usersession);
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
                status = "There seems to be an issue with updating access token. Please try again.";
            }

            return(status);
        }
Beispiel #2
0
        public ActionResult Register(Account account)
        {
            account.IsAdmin = admin;
            // account.Password = Encrypt(account.Password);


            if (ModelState.IsValid)
            {
                db.Accounts.Add(account);


                try {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    if (ex is System.Data.SqlClient.SqlException || ex is System.Data.Entity.Infrastructure.DbUpdateException)
                    {
                        ViewBag.ErrorMsg = "The Email/Username already Exists in our database, kindly use another one";
                        return(View());
                    }

                    //throw;
                }
                return(RedirectToAction("Login", "Accounts"));
            }

            return(View(account));
        }
Beispiel #3
0
        private void AddMovie()
        {
            if (txbMovieTitle.Text == "" ||
                txbMovieYear.Text == "" ||
                txbMovieReleaseCountry.Text == "" ||
                txbMovieTime.Text == "" ||
                txbMovieLanguage.Text == "")
            {
                MessageBox.Show("Thông tin chưa đủ");
            }

            try
            {
                movie movie = new movie();
                movie.mov_title       = txbMovieTitle.Text;
                movie.mov_year        = Convert.ToInt32(txbMovieYear.Text);
                movie.mov_rel_country = txbMovieReleaseCountry.Text;
                movie.mov_time        = Convert.ToInt32(txbMovieTime.Text);
                movie.mov_lang        = txbMovieLanguage.Text;
                movie.mov_dt_rel      = dpMovieReleaseDate.Value;
                movie.mov_image       = txbMovieImage.Text;

                db.movies.Add(movie);
                db.SaveChanges();

                MessageBox.Show("Thêm movie thành công");

                ReloadDataGird();
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm movie thất bại");
            }
        }
Beispiel #4
0
        private void AddDirector()
        {
            if (txbDirectorFirstName.Text == "" ||
                txbDirectorLastName.Text == "")
            {
                MessageBox.Show("Thông tin chưa đủ");
            }

            try
            {
                director director = new director();
                director.dir_fname = txbDirectorFirstName.Text;
                director.dir_lname = txbDirectorLastName.Text;
                director.dir_image = txbDirectorImage.Text;

                db.directors.Add(director);
                db.SaveChanges();

                MessageBox.Show("Thêm actor thành công");

                ReloadDataGird();
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm actor thất bại");
            }
        }
Beispiel #5
0
        public void AddActor()
        {
            if (txbActorFirstName.Text == "" ||
                txbActorLastName.Text == "" ||
                cbbActorGender.selectedValue == "")
            {
                MessageBox.Show("Thông tin chưa đủ");
            }

            try
            {
                actor actor = new actor();
                actor.act_fname  = txbActorFirstName.Text;
                actor.act_lname  = txbActorLastName.Text;
                actor.act_gender = cbbActorGender.selectedValue;
                actor.act_image  = txbActorImage.Text;
                db.actors.Add(actor);
                db.SaveChanges();

                MessageBox.Show("Thêm actor thành công");

                ReloadDataGird();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thêm actor thất bại");
            }
        }
        public static Dictionary <string, object> like(int commentId)
        {
            MovieEntities movieEntities        = new MovieEntities();
            int           userId               = SessionService.getSession();
            Like          like                 = movieEntities.Like.Where(m => m.user_id == userId && m.comment_id == commentId).FirstOrDefault();
            Comment       comment              = movieEntities.Comment.Where(c => c.id == commentId).FirstOrDefault();
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (like == null)
            {
                Like newLike = new Like();
                newLike.user_id    = userId;
                newLike.comment_id = commentId;
                movieEntities.Like.Add(newLike);
                comment.likes += 1;
                movieEntities.SaveChanges();
                result.Add("like", true);
                result.Add("likes", comment.likes);
            }
            else
            {
                movieEntities.Like.Remove(like);
                comment.likes -= 1;
                movieEntities.SaveChanges();
                result.Add("like", false);
                result.Add("likes", comment.likes);
            }
            return(result);
        }
Beispiel #7
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create(/*[Bind(Include = "Id,MovieID")] */ Favourite favourite)
        {
            if (Session["Username"] != null)
            {
                if (ModelState.IsValid)
                {
                    db.Favourites.Add(favourite);
                    try
                    {
                        db.SaveChanges();
                        return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                    }
                }

                ViewBag.Id = new SelectList(db.Accounts, "Id", "EmailID", favourite.Id);
                return(View(favourite));
            }
            else
            {
                return(RedirectToAction("Login", "Accounts"));
            }
        }
        private static void LoadDataIntoDb(dynamic obj, int path)
        {
            try
            {
                MovieEntities db = new MovieEntities();

                string imdbId = obj[0]["imdb_id"];

                //if(!db.Movies.Select(m => m.ImdbID == imdbId).First())
                if (db.Movies.Count() == 0 || !db.Movies.Select(m => m.ImdbID == imdbId).First())
                {
                    Int64 existingMovieId = 0;
                    if (db.Movies.Count() > 0)
                    {
                        existingMovieId = db.Movies.Count();
                    }
                    Movie movie = new Movie();
                    movie.ID           = existingMovieId + 1;
                    movie.PlotDetailed = obj[0]["plot"];
                    movie.ImdbID       = obj[0]["imdb_id"];
                    movie.PlotSimple   = obj[0]["plot_simple"];
                    var tempruntime = obj[0]["runtime"];
                    movie.Runtime    = ConvertRuntime(tempruntime.ToString());
                    movie.Rated      = obj[0]["rated"];
                    movie.ImdbUrl    = obj[0]["imdb_url"];
                    movie.AKA        = obj[0]["also_known_as"][0];
                    movie.IMDBRating = obj[0]["rating"];
                    Int64    releaseDate = obj[0]["release_date"];
                    DateTime dtTime      = new DateTime(Int32.Parse(releaseDate.ToString().Substring(0, 4)), Int32.Parse(releaseDate.ToString().Substring(4, 2)), Int32.Parse(releaseDate.ToString().Substring(6, 2)));
                    movie.ReleaseDate = dtTime;
                    movie.Title       = obj[0]["title"];
                    Genres(obj, db);
                    db.Movies.Add(movie);
                    db.SaveChanges();
                    var savedMovie = db.Movies.Where(m => m.ImdbID == movie.ImdbID).Distinct();

                    MoviePersonRole(obj, db);
                    var    ListOfGenre = obj[0]["genres"];
                    Poster poster      = new Poster();
                    poster.imdb  = obj[0]["poster"]["imdb"];
                    poster.cover = obj[0]["poster"]["cover"];
                    PosterInfo posterInfo = new PosterInfo();
                    posterInfo.Imdb    = poster.imdb;
                    posterInfo.Cover   = poster.cover;
                    posterInfo.MovieId = savedMovie.First().ID;
                    db.PosterInfoes.Add(posterInfo);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                string inputfolder = "C:\\Users\\PrashMaya\\My Documents\\Exceptions\\Movie{0}.txt";
                string inputfile   = String.Format(inputfolder, path);
                System.IO.File.WriteAllText(inputfile, ex.ToString());
                Console.WriteLine(ex.Message);
            }
        }
        public ActionResult Create([Bind(Include = "Admin_ID,Admin_Name,Admin_Password,DateOfBirth,Admin_Contact")] AdminTable adminTable)
        {
            if (ModelState.IsValid)
            {
                db.AdminTables.Add(adminTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(adminTable));
        }
Beispiel #10
0
        public ActionResult Create([Bind(Include = "Id,Name,Sex,DOB,Bio")] Producer producer)
        {
            if (ModelState.IsValid)
            {
                db.Producers.Add(producer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(producer));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "Name,Id,Sex,DOB,Bio")] Actor actor)
        {
            if (ModelState.IsValid)
            {
                db.Actors.Add(actor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(actor));
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "Name,Plot,Poster,Release_Year,Producer_Id,Id")] Movy movy)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Producer_Id = new SelectList(db.Producers, "Id", "Name", movy.Producer_Id);
            return(View(movy));
        }
        public ActionResult Create([Bind(Include = "Id,Actor_Id,Movie_Id")] Movie_Actors movie_Actors)
        {
            if (ModelState.IsValid)
            {
                db.Movie_Actors.Add(movie_Actors);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Actor_Id = new SelectList(db.Actors, "Id", "Name", movie_Actors.Actor_Id);
            ViewBag.Movie_Id = new SelectList(db.Movies, "Id", "Name", movie_Actors.Movie_Id);
            return(View(movie_Actors));
        }
Beispiel #14
0
        public static Dictionary <string, object> Register(string email, string pwd, string name)
        {
            MovieEntities movieEntities        = new MovieEntities();
            Dictionary <string, object> result = new Dictionary <string, object>();
            User user = movieEntities.User.Where(u => u.email.Equals(email)).FirstOrDefault();

            if (user == null)
            {
                user = new User
                {
                    email    = email,
                    password = pwd,
                    name     = name
                };
                movieEntities.User.Add(user);
                movieEntities.SaveChanges();
                HttpContext.Current.Session["user"] = user.id;
                result.Add("type", ConstantValue.RegisterSucceed);
                result.Add("id", movieEntities.User.Where(u => u.email.Equals(email)).FirstOrDefault().id);
                return(result);
            }
            else
            {
                result.Add("type", ConstantValue.UserExist);
                return(result);
            }
        }
Beispiel #15
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            // Lay thong tin tren man hinh giao dien
            string username = txbUsername.Text;
            string password = txbPassword.Text;

            // Kiem tra user co ton tai trong database hay khong
            bool hasUser = db.users.Any(x => x.user_name == username && x.user_password == password);

            if (hasUser == true)
            {
                MessageBox.Show("Tài khoản đã tồn tại, đăng ký thất bại");
            }
            else
            {
                string type = cbbUserType.selectedValue;

                user newUser = new user();
                newUser.user_name     = username;
                newUser.user_password = password;
                newUser.user_type     = type;

                try
                {
                    db.users.Add(newUser);
                    db.SaveChanges();
                    MessageBox.Show("Đăng ký thành công");
                }
                catch (Exception)
                {
                    MessageBox.Show("Đăng ký thất bại");
                }
            }
        }
        public void InsertOrUpdateComment(int userId, int movieId, decimal score)
        {
            DateTime now = DateTime.UtcNow;

            using (var db = new MovieEntities())
            {
                var target = db.UserCommentMovies.FirstOrDefault(m => m.UserId == userId &&
                                                                 m.MovieId == movieId);


                if (target == null)
                {
                    db.UserCommentMovies.Add(new UserCommentMovie
                    {
                        UserId     = userId,
                        MovieId    = movieId,
                        Score      = score,
                        AddTime    = now,
                        UpdateTime = now
                    });
                }
                else
                {
                    target.Score      = score;
                    target.UpdateTime = now;
                }

                db.SaveChanges();
            }
        }
Beispiel #17
0
        /// <summary>
        /// 删除token
        /// </summary>
        /// <param name="UserId"></param>
        private static void DeleteToken(int UserId)
        {
            MovieEntities dc   = new MovieEntities();
            var           list = dc.Tokens.Where(c => c.UserID == UserId).FirstOrDefault();

            dc.Tokens.Remove(list);
            dc.SaveChanges();
        }
Beispiel #18
0
        public bool CreateMovie(DataAccess.Movie movie)     //新增電影
        {
            MovieEntities dbMovie = new MovieEntities();

            dbMovie.Movie.Add(movie);
            dbMovie.SaveChanges();
            return(true);
        }
 public static void Delete(int id)
 {
     using (MovieEntities context = new MovieEntities())
     {
         var movie = context.Movies.Where(x => x.ID == id).First();
         context.Movies.Remove(movie);
         context.SaveChanges();
     }
 }
        /// <summary>
        /// 保存订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <param name="orderID"></param>
        private void SaveOrderDetails(OrderModel model, int orderID)
        {
            List <OrderDetails> list = new List <OrderDetails>();

            for (int i = 0; i < model.SeatList.Count; i++)
            {
                list.Add(new OrderDetails
                {
                    Day     = DateTime.Now,
                    OrderID = orderID,
                    TimeID  = model.TimeID,
                    Col     = model.SeatList[i].Col,
                    Row     = model.SeatList[i].Row
                });
            }
            //保存提交信息
            dc.OrderDetails.Add(list.FirstOrDefault());
            dc.SaveChanges();
        }
        private static void AddSampleRoleData()
        {
            Role role = new Role();

            role.Description = "Director";
            MovieEntities db = new MovieEntities();

            db.Roles.Add(role);
            db.SaveChanges();
        }
Beispiel #22
0
        public void deleteMovie(int?movieId)
        {
            using (MovieEntities db = new MovieEntities())
            {
                // delete from MoviesGenre

                var genre = (from m in db.MoviesGenres where m.Movies_ID == movieId select m).ToList();
                if (genre.Count() > 0)
                {
                    foreach (var item in genre)
                    {
                        db.MoviesGenres.Remove(item);
                        db.SaveChanges();
                    }
                }


                // delete from ActorMovies

                var actor = (from m in db.ActorMovies where m.Movies_ID == movieId select m).ToList();
                if (actor.Count() > 0)
                {
                    foreach (var item in actor)
                    {
                        db.ActorMovies.Remove(item);
                        db.SaveChanges();
                    }
                }

                // delete from Movies
                var result = (from m in db.Movies where m.Movies_ID == movieId select m).ToList();
                if (result.Count() > 0)
                {
                    foreach (var item in result)
                    {
                        db.Movies.Remove(item);
                        db.SaveChanges();
                    }
                }
            }
        }
Beispiel #23
0
 public IHttpActionResult Register([FromBody] Users u)
 {
     if (u != null)
     {
         var list = dc.Users.Where(c => c.UserName == u.UserName);
         if (list.Count() > 0)
         {
             return(StatusCode(HttpStatusCode.Conflict));
         }
         else
         {
             dc.Users.Add(u);
             dc.SaveChanges();
             return(Ok());
         }
     }
     else
     {
         return(BadRequest());
     }
 }
Beispiel #24
0
        public bool UpdateMovie(DataAccess.Movie movie)     //更新電影
        {
            MovieEntities dbMovie = new MovieEntities();

            DataAccess.Movie queryMovie = dbMovie.Movie.FirstOrDefault(x => x.ID == movie.ID);
            if (queryMovie != null)
            {
                dbMovie.Entry(queryMovie).CurrentValues.SetValues(movie);
                dbMovie.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #25
0
        public bool DeleteMovie(int movieID)        //刪除電影
        {
            MovieEntities dbMovie = new MovieEntities();

            DataAccess.Movie queryMovie = dbMovie.Movie.FirstOrDefault(x => x.ID == movieID);
            if (queryMovie != null)
            {
                dbMovie.Movie.Remove(queryMovie);
                dbMovie.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #26
0
        public string rentMovies(RentMoviesRequestJSON res)
        {
            string status = "";

            try
            {
                using (MovieEntities db = new MovieEntities())
                {
                    foreach (var item in res.moviesIds)
                    {
                        UsersRental ur = new UsersRental();
                        ur.Users_ID  = res.userId;
                        ur.Movies_ID = item;
                        DateTime datefrom = convertToDate(res.RentalDateFrom);
                        DateTime dateto   = convertToDate(res.RentalDateTo);
                        if (datefrom == DateTime.Now)
                        {
                            ur.RentalDateFrom = null;
                        }
                        else
                        {
                            ur.RentalDateFrom = datefrom;
                        }
                        if (dateto == DateTime.Now)
                        {
                            ur.RentalDateTo = null;
                        }
                        else
                        {
                            ur.RentalDateTo = dateto;
                        }
                        ur.UsersTransaction_ID = null;
                        ur.CreatedDate         = DateTime.UtcNow;
                        db.UsersRentals.Add(ur);
                        db.SaveChanges();
                    }

                    /* if authorizePayment is set to true user credit card details can obtained from Users table.
                     * if true, we can get these details from Users table and charge accordingly using Stripe or Authorize.net library
                     */
                    status = "Rented successfully";
                }
            }
            catch
            {
                status = "ERR: There seems to be issue with rental. Please try again.";
            }

            return(status);
        }
Beispiel #27
0
        private void AddGenres()
        {
            if (txbGenresTitle.Text == "")
            {
                MessageBox.Show("Thông tin chưa đủ");
            }

            try
            {
                genre genre = new genre();
                genre.gen_title = txbGenresTitle.Text;
                db.genres.Add(genre);
                db.SaveChanges();

                MessageBox.Show("Thêm genres thành công");

                ReloadDataGird();
            }
            catch (Exception)
            {
                MessageBox.Show("Thêm genres thất bại");
            }
        }
Beispiel #28
0
        public static Record save(int userId, int movieId, string content)
        {
            Record record = new Record
            {
                user_id  = userId,
                movie_id = movieId,
                time     = DateTime.Now,
                content  = content
            };
            MovieEntities movieEntities = new MovieEntities();

            movieEntities.Record.Add(record);
            movieEntities.SaveChanges();
            return(record);
        }
        public static Dictionary <string, object> reply(int commentId, int atId, string content, int replyId)
        {
            MovieEntities movieEntities = new MovieEntities();
            int           userId        = SessionService.getSession();
            Feedback      feedback      = new Feedback();

            feedback.comment_id = commentId;
            feedback.user_id    = userId;
            feedback.at_id      = atId;
            feedback.reply_id   = replyId;
            feedback.content    = content;
            feedback.time       = DateTime.Now;
            movieEntities.Feedback.Add(feedback);
            movieEntities.SaveChanges();
            return(ClassToDictionary.classToDictionary(feedback));
        }
        public static void Edit(int id, string title, DateTime releaseDate, decimal price, List <int> genres)
        {
            using (MovieEntities context = new MovieEntities())
            {
                var movie = context.Movies.Where(x => x.ID == id).First();
                movie.Title       = title;
                movie.ReleaseDate = releaseDate;
                movie.Genres.Clear();
                foreach (var genreID in genres)
                {
                    var genre = context.Genres.Find(genreID);
                    movie.Genres.Add(genre);
                }

                context.SaveChanges();
            }
        }