Beispiel #1
0
        public async Task <ResponseEntity> LayDanhSachPhimTheoNgay(string maNhom = "GP01", string tenPhim = "", int soTrang = 1, int soPhanTuTrenTrang = 10, string tuNgay = "", string denNgay = "")
        {
            DateTime dtTuNgay  = DateTimes.Now();
            DateTime dtDenNgay = DateTimes.Now();

            if (tuNgay != "")
            {
                try
                {
                    dtTuNgay = DateTimes.ConvertDate(tuNgay);
                }
                catch (Exception ex)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày không hợp lệ", MessageConstant.MESSAGE_ERROR_400));
                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày không hợp lệ, Ngày có định dạng dd/MM/yyyy !");
                }
            }
            if (denNgay != "")
            {
                try
                {
                    dtDenNgay = DateTimes.ConvertDate(denNgay);
                }
                catch (Exception ex)
                {
                    //return new ResponseEntity(StatusCodeConstants.OK, "Ngày không hợp lệ", MessageConstant.MESSAGE_SUCCESS_200);

                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày không hợp lệ, Ngày có định dạng dd/MM/yyyy !", MessageConstant.MESSAGE_ERROR_400));
                }
            }
            bool ckNhom = db.Nhom.Any(n => n.MaNhom == maNhom);

            if (!ckNhom)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!");

                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Nhóm người dùng không hợp lệ", MessageConstant.MESSAGE_ERROR_400));;
            }
            tenPhim = LoaiBoKyTu.bestLower(tenPhim);
            IEnumerable <PhimVM> lstResult = db.Phim.Where(n => n.BiDanh.Contains(tenPhim) && n.MaNhom == maNhom && n.DaXoa != true && n.NgayKhoiChieu.Value >= dtTuNgay.Date && n.NgayKhoiChieu.Value <= dtDenNgay.Date).Select(n => new PhimVM {
                MaPhim = n.MaPhim, BiDanh = n.BiDanh, DanhGia = n.DanhGia, HinhAnh = DomainImage + n.HinhAnh, MaNhom = n.MaNhom, MoTa = n.MoTa, TenPhim = n.TenPhim, Trailer = n.Trailer, NgayKhoiChieu = n.NgayKhoiChieu, Hot = n.Hot, DangChieu = n.DangChieu, SapChieu = n.SapChieu
            });

            var model = PagingList.Create(lstResult, soPhanTuTrenTrang, soTrang);

            return(new ResponseEntity(StatusCodeConstants.OK, model, MessageConstant.MESSAGE_SUCCESS_200));
        }
        public async Task <object> CapNhatPhim(PhimViewModel phimUpdate)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                IEnumerable <Phim> listPhim = connection.Query <Phim>("SELECT * FROM [dbo].[PHIM]", commandType: CommandType.Text);
                var phim = listPhim.Where(n => n.MaPhim == phimUpdate.MaPhim);
                if (phim == null)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã phim không hợp lệ!"));
                }
                string tenPhim = LoaiBoKyTu.bestLower(phimUpdate.TenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!"));
                }
                var p = listPhim.Where(n => n.BiDanh == tenPhim);
                if (p.Count() > 2)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!"));
                }

                //Kiểm tra hình ảnh và trailer
                if (phimUpdate.HinhAnh.Split('.').Count() > 1)
                {
                    phimUpdate.HinhAnh = LoaiBoKyTu.bestLower(phimUpdate.TenPhim) + "." + phimUpdate.HinhAnh.Split('.')[phimUpdate.HinhAnh.Split('.').Length - 1];
                }
                else
                {
                    var response = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Hình ảnh không đúng định dạng!");

                    return(response);
                }
                if (!string.IsNullOrEmpty(phimUpdate.Trailer))
                {
                    string newString = phimUpdate.Trailer.Replace("https://www.youtube.com/embed/", "♥");
                    if (newString.Split('♥').Length == 1)
                    {
                        return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]"));
                    }
                }

                DateTime temp;
                try
                {
                    try
                    {
                        temp = DateTimes.ConvertDate(phimUpdate.NgayKhoiChieu);
                    }
                    catch (Exception ex)
                    {
                        return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
                    }
                }
                catch (Exception ex)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
                }

                var param = new DynamicParameters();
                param.Add("@MAPHIM", phimUpdate.MaPhim);
                param.Add("@TENPHIM", phimUpdate.TenPhim);
                param.Add("@TRAILER", phimUpdate.Trailer);
                param.Add("@HINHANH", hostName + phimUpdate.HinhAnh);
                param.Add("@MOTA", phimUpdate.MoTa);
                param.Add("@NGAYKHOICHIEU", temp);
                param.Add("@DANHGIA", phimUpdate.DanhGia);
                param.Add("@DIENVIEN", phimUpdate.DienVien);
                param.Add("@DAODIEN", phimUpdate.DaoDien);
                param.Add("@DOTUOI", phimUpdate.DoTuoi);
                param.Add("@BIDANH", phimUpdate.BiDanh);
                param.Add("@DAXOA", phimUpdate.DaXoa);
                param.Add("@KHOICHIEU", phimUpdate.KhoiChieu);
                param.Add("@SAPCHIEU", phimUpdate.SapChieu);
                await connection.QueryAsync <Phim>("PHIM_UPDATE", param, commandType : CommandType.StoredProcedure);

                return("Cập nhật phim thành công!");
            }
        }
Beispiel #3
0
        public async Task <ResponseEntity> CapNhatPhimUpload([FromForm] IFormCollection frm)
        {
            PhimUpload model = new PhimUpload();

            model        = (PhimUpload)Convert(frm, model);
            model.maPhim = int.Parse(frm["maPhim"]);
            model.maNhom = model.maNhom.ToUpper();
            if (Request.Form.Files.Count > 0)
            {
                model.hinhAnh = Request.Form.Files[0];
            }

            if (string.IsNullOrEmpty(model.ngayKhoiChieu))
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !", MessageConstant.MESSAGE_ERROR_400));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
            }
            model.biDanh = LoaiBoKyTu.bestLower(model.tenPhim);
            try
            {
                Phim phimUpdate = db.Phim.SingleOrDefault(n => n.MaPhim == model.maPhim);
                if (phimUpdate == null)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Mã phim không tồn tại!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã phim không tồn tại!");
                }
                model.maNhom = model.maNhom.ToUpper();
                bool ckb = db.Nhom.Any(n => n.MaNhom == model.maNhom);
                if (!ckb)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Mã nhóm không hợp lệ!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã nhóm không hợp lệ!");
                }
                string tenPhim = LoaiBoKyTu.bestLower(model.tenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tên phim không hợp lệ!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!");
                }
                var p      = db.Phim.Where(n => n.BiDanh == model.biDanh);
                int length = p.Count();
                //if (p.Count() > 2)
                //{
                //    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!");
                //}


                phimUpdate.TenPhim = model.tenPhim;
                phimUpdate.BiDanh  = LoaiBoKyTu.bestLower(model.tenPhim);

                phimUpdate.Trailer   = model.trailer;
                phimUpdate.MoTa      = model.moTa;
                phimUpdate.MoTa      = model.moTa;
                phimUpdate.TenPhim   = model.tenPhim;
                phimUpdate.Trailer   = model.trailer;
                phimUpdate.Hot       = model.Hot;
                phimUpdate.SapChieu  = model.SapChieu;
                phimUpdate.DangChieu = model.DangChieu;
                if (model.hinhAnh != null)
                {
                    //phimUpdate.HinhAnh = model.HinhAnh;
                    phimUpdate.HinhAnh = LoaiBoKyTu.bestLower(model.tenPhim) + "_" + LoaiBoKyTu.bestLower(model.maNhom) + "." + model.hinhAnh.FileName.Split('.')[model.hinhAnh.FileName.Split('.').Length - 1];
                    string kq = UploadHinhAnh(model.hinhAnh, model.tenPhim, model.maNhom);
                    if (kq.Trim() != "")
                    {
                        return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, kq, MessageConstant.MESSAGE_ERROR_500));

                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, kq);
                    }
                }
                phimUpdate.DanhGia = model.danhGia;
                DateTime temp;
                try
                {
                    try
                    {
                        phimUpdate.NgayKhoiChieu = DateTimes.ConvertDate(model.ngayKhoiChieu);
                    }
                    catch (Exception ex)
                    {
                        phimUpdate.NgayKhoiChieu = DateTime.Now;
                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
                    }
                }
                catch (Exception ex)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !", MessageConstant.MESSAGE_ERROR_400));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
                }

                if (!string.IsNullOrEmpty(model.trailer))
                {
                    string newString = phimUpdate.Trailer.Replace("https://www.youtube.com/embed/", "♥");
                    if (newString.Split('♥').Length == 0)
                    {
                        return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]", MessageConstant.MESSAGE_ERROR_500));

                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]");
                    }
                }
                db.SaveChanges();
                return(new ResponseEntity(StatusCodeConstants.OK, model, MessageConstant.MESSAGE_SUCCESS_200));

                //return Ok(model);
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Dữ liệu không hợp lệ!", MessageConstant.MESSAGE_ERROR_500));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!");
            }
        }
Beispiel #4
0
        //[Authorize(Roles = "QuanTri")]
        public async Task <ResponseEntity> ThemPhimUploadHinh([FromForm] IFormCollection frm)
        {
            try
            {
                PhimUpload model = new PhimUpload();
                model        = (PhimUpload)Convert(frm, model);
                model.maNhom = model.maNhom.ToUpper();
                if (string.IsNullOrEmpty(model.maNhom))
                {
                    model.maNhom = "GP01";
                }

                if (Request.Form.Files[0] == null)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Chưa chọn hình ảnh !", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Chưa chọn hình ảnh !");
                }


                model.hinhAnh = Request.Form.Files[0];
                string request = Request.Form["tenPhim"];;
                bool   ckb     = db.Nhom.Any(n => n.MaNhom == model.maNhom);
                if (!ckb)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Mã nhóm không hợp lệ!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã nhóm không hợp lệ!");
                }
                string tenPhim = LoaiBoKyTu.bestLower(model.tenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tên phim không hợp lệ!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!");
                }
                var p = db.Phim.Where(n => n.BiDanh == model.biDanh);
                if (p.Count() > 1)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tên phim đã tồn tại!", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!");
                }


                //PhimInsertNew phimNew = Mapper.Map<PhimInsert, PhimInsertNew>(model)
                Phim modelInsert = new Phim();
                modelInsert.BiDanh  = LoaiBoKyTu.bestLower(model.tenPhim);
                modelInsert.DanhGia = model.danhGia;
                modelInsert.DaXoa   = false;
                modelInsert.MaPhim  = 0;
                modelInsert.HinhAnh = LoaiBoKyTu.bestLower(model.tenPhim) + "_" + LoaiBoKyTu.bestLower(model.maNhom) + "." + model.hinhAnh.FileName.Split('.')[model.hinhAnh.FileName.Split('.').Length - 1];
                //modelInsert.MaNhom = LoaiBoKyTu.bestLower(model.maNhom);
                modelInsert.MoTa      = model.moTa;
                modelInsert.TenPhim   = model.tenPhim;
                modelInsert.Trailer   = model.trailer;
                modelInsert.Hot       = model.Hot;
                modelInsert.SapChieu  = model.SapChieu;
                modelInsert.DangChieu = model.DangChieu;
                DateTime temp;
                try
                {
                    try
                    {
                        modelInsert.NgayKhoiChieu = DateTimes.ConvertDate(model.ngayKhoiChieu);
                    }
                    catch (Exception ex)
                    {
                        return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy!", MessageConstant.MESSAGE_ERROR_500));

                        //return new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy!", MessageConstant.MESSAGE_ERROR_500);
                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
                    }
                }
                catch (Exception ex)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
                }

                if (!string.IsNullOrEmpty(modelInsert.Trailer))
                {
                    string newString = modelInsert.Trailer.Replace("https://www.youtube.com/embed/", "♥");
                    if (newString.Split('♥').Length == 0)
                    {
                        return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]", MessageConstant.MESSAGE_ERROR_500));

                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]");
                    }
                }
                db.Phim.Add(modelInsert);
                string kq = UploadHinhAnh(model.hinhAnh, modelInsert.TenPhim, modelInsert.MaNhom);
                if (kq != "")
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, kq, MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, kq);
                }
                modelInsert.MaNhom = model.maNhom.ToUpper();

                db.SaveChanges();

                return(new ResponseEntity(StatusCodeConstants.OK, kq, MessageConstant.MESSAGE_SUCCESS_200));

                //return Ok(modelInsert);
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "thuộc tính hinhAnh không đúng định dạng *.jpg, *.png, *.gif!", MessageConstant.MESSAGE_ERROR_400));


                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "thuộc tính hinhAnh không đúng định dạng *.jpg, *.png, *.gif!");
            }
        }
        public async Task <ActionResult> CapNhatPhim(PhimInsert model)
        {
            if (string.IsNullOrEmpty(model.NgayKhoiChieu))
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
            }
            //dbRapChieuPhimContext dbo = new dbRapChieuPhimContext();
            ////Fixembed
            //var lstPhim = db.Phim;
            //foreach (var item in lstPhim)
            //{
            //    var p = dbo.Phim.Single(n => n.MaPhim == item.MaPhim);
            //    string s = item.Trailer.Split('=')[item.Trailer.Split('=').Length - 1];
            //    p.Trailer = @"https://www.youtube.com/embed/" + s;

            //    dbo.SaveChanges();
            //}
            model.BiDanh = LoaiBoKyTu.bestLower(model.TenPhim);
            try
            {
                Phim phimUpdate = db.Phim.SingleOrDefault(n => n.MaPhim == model.MaPhim);
                if (phimUpdate == null)
                {
                    return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã phim không tồn tại!"));
                }
                model.MaNhom = model.MaNhom.ToUpper();
                bool ckb = db.Nhom.Any(n => n.MaNhom == model.MaNhom);
                if (!ckb)
                {
                    return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã nhóm không hợp lệ!"));
                }
                string tenPhim = LoaiBoKyTu.bestLower(model.TenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!"));
                }
                var p = db.Phim.Where(n => n.BiDanh == model.BiDanh);
                if (p.Count() > 2)
                {
                    return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!"));
                }


                phimUpdate.TenPhim = model.TenPhim;
                phimUpdate.BiDanh  = LoaiBoKyTu.bestLower(model.TenPhim);

                phimUpdate.Trailer = model.Trailer;
                phimUpdate.MoTa    = model.MoTa;
                phimUpdate.HinhAnh = model.HinhAnh;
                phimUpdate.DanhGia = model.DanhGia;

                Phim pCu = db.Phim.Where(n => n.MaPhim == model.MaPhim).FirstOrDefault();

                if (string.IsNullOrEmpty(model.HinhAnh))
                {
                    if (pCu != null)
                    {
                        phimUpdate.HinhAnh = pCu.HinhAnh;
                    }
                }

                DateTime temp;
                try
                {
                    try
                    {
                        phimUpdate.NgayKhoiChieu = DateTimes.ConvertDate(model.NgayKhoiChieu);
                    }
                    catch (Exception ex)
                    {
                        return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
                    }
                }
                catch (Exception ex)
                {
                    return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày khởi chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
                }
                if (model.HinhAnh != null)
                {
                    if (model.HinhAnh.Split('.').Count() > 1)
                    {
                        phimUpdate.HinhAnh = LoaiBoKyTu.bestLower(phimUpdate.TenPhim) + "_" + LoaiBoKyTu.bestLower(phimUpdate.MaNhom) + "." + phimUpdate.HinhAnh.Split('.')[phimUpdate.HinhAnh.Split('.').Length - 1];
                    }
                    else
                    {
                        var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Hình ảnh không đúng định dạng!");

                        return(response);
                    }
                }
                if (!string.IsNullOrEmpty(model.Trailer))
                {
                    string newString = phimUpdate.Trailer.Replace("https://www.youtube.com/embed/", "♥");
                    if (newString.Split('♥').Length == 0)
                    {
                        return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]"));
                    }
                }
                db.SaveChanges();
                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!"));
            }
        }
        public async Task <ResponseEntity> ThemPhim(PhimInsert model)
        {
            model.BiDanh = LoaiBoKyTu.bestLower(model.TenPhim);
            try
            {
                model.MaNhom = model.MaNhom.ToUpper();
                bool ckb = db.Nhom.Any(n => n.MaNhom == model.MaNhom);
                if (!ckb)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày không hợp lệ, Ngày có định dạng dd/MM/yyyy !", MessageConstant.MESSAGE_ERROR_400));
                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã nhóm không hợp lệ!");
                }
                string tenPhim = LoaiBoKyTu.bestLower(model.TenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Tên phim không hợp lệ !", MessageConstant.MESSAGE_ERROR_400));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!");
                }
                var p = db.Phim.Where(n => n.BiDanh == model.BiDanh);
                if (p.Count() > 1)
                {
                    return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tên phim đã tồn tại !", MessageConstant.MESSAGE_ERROR_500));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!");
                }


                PhimInsertNew phimNew     = Mapper.Map <PhimInsert, PhimInsertNew>(model);
                Phim          modelInsert = Mapper.Map <PhimInsertNew, Phim>(phimNew);
                modelInsert.BiDanh = LoaiBoKyTu.bestLower(modelInsert.TenPhim);
                //DateTime temp;
                //if (DateTime.TryParse(model.NgayKhoiChieu, out temp))
                //{
                try
                {
                    modelInsert.NgayKhoiChieu = DateTimes.ConvertDate(model.NgayKhoiChieu);
                }
                catch (Exception ex)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy!", MessageConstant.MESSAGE_ERROR_400));

                    //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
                }
                //}
                //else
                //{

                //}

                if (modelInsert.HinhAnh.Split('.').Count() > 1)
                {
                    modelInsert.HinhAnh = LoaiBoKyTu.bestLower(modelInsert.TenPhim) + "_" + LoaiBoKyTu.bestLower(modelInsert.MaNhom) + "." + modelInsert.HinhAnh.Split('.')[modelInsert.HinhAnh.Split('.').Length - 1];
                }
                else
                {
                    //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Hình ảnh không đúng định dạng!");
                    return(new ResponseEntity(StatusCodeConstants.OK, "Hình ảnh không đúng định dạng!", MessageConstant.MESSAGE_SUCCESS_200));
                }
                if (!string.IsNullOrEmpty(modelInsert.Trailer))
                {
                    string newString = modelInsert.Trailer.Replace("https://www.youtube.com/embed/", "♥");
                    if (newString.Split('♥').Length == 0)
                    {
                        //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Link trailer không hợp lệ link trailer phải có định dạng: https://www.youtube.com/embed/[thamso]");
                        return(new ResponseEntity(StatusCodeConstants.OK, "Hình ảnh không đúng định dạng!", MessageConstant.MESSAGE_SUCCESS_200));
                    }
                }
                modelInsert.MaPhim = 0;
                db.Phim.Add(modelInsert);
                db.SaveChanges();

                return(new ResponseEntity(StatusCodeConstants.OK, modelInsert, MessageConstant.MESSAGE_SUCCESS_200));
                //return Ok(modelInsert);
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "thuộc tính hinhAnh không đúng định dạng *.jpg, *.png, *.gif!", MessageConstant.MESSAGE_ERROR_500));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "thuộc tính hinhAnh không đúng định dạng *.jpg, *.png, *.gif!");
            }
        }