public async Task <ResponseEntity> ThemNguoiDung(NguoiDungVM nd)
        {
            nd.MaNhom = nd.MaNhom.ToUpper();
            bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung);

            if (!ckbLoaiND)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Loại người dùng không hợp lệ!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!");
                //return response;
            }
            bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom);

            if (!ckNhom)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Nhóm người dùng không hợp lệ!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!");
                //return response;
            }
            bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email);

            if (ckEmail)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Email đã tồn tại!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!");
                //return response;
            }
            var nguoiDung = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan);

            if (nguoiDung != null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tài khoản đã tồn tại!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản đã tồn tại!");
                //return response;
            }
            try
            {
                NguoiDung ndInsert = Mapper.Map <NguoiDungVM, NguoiDung>(nd);
                ndInsert.BiDanh = LoaiBoKyTu.bestLower(ndInsert.HoTen);
                db.NguoiDung.Add(ndInsert);
                db.SaveChanges();
                return(new ResponseEntity(StatusCodeConstants.OK, nd, MessageConstant.MESSAGE_SUCCESS_200));

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

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!");
                //return response;
            }
        }
        public async Task <IActionResult> UploadHinhAnhPhim()
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }

                IFormFile file    = Request.Form.Files[0];
                string    tenPhim = Request.Form["tenPhim"];
                tenPhim = LoaiBoKyTu.bestLower(tenPhim);

                if (string.IsNullOrEmpty(tenPhim))
                {
                    var result = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ");

                    return(Ok(result));
                }

                //if (file.Length > TenMegaBytes)
                //{
                //    var result = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Dung lượng file vượt quá 1 MB!");
                //    return Ok(result);
                //}
                if (file.ContentType == "image/png" || file.ContentType == "image/jpeg" || file.ContentType == "image/jpg" || file.ContentType == "image/gif")
                {
                    try
                    {
                        // Kiểm tra tên phim có tồn tại hay không để upload ảnh
                        var kh = connection.Query("SELECT * FROM dbo.Phim WHERE BiDanh = '" + tenPhim + "'", commandType: CommandType.Text);
                        if (kh.Count() == 0)
                        {
                            var result = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Phim không tồn tại không thể upload file");

                            return(Ok(result));
                        }

                        var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/HinhAnh", tenPhim + "." + file.FileName.Split('.')[file.FileName.Split('.').Length - 1]);
                        var stream = new FileStream(path, FileMode.Create);
                        file.CopyTo(stream);
                        return(Ok("Upload file thành công !"));
                    }
                    catch
                    {
                        var response = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Upload file không thành công!");

                        return(Ok(response));
                    }
                }
                else
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Định dạng file không hợp lệ!"));
                }
            }
        }
        public string UploadHinhAnh(IFormFile file, string tenPhim, string maNhom)
        {
            file    = Request.Form.Files[0];
            tenPhim = Request.Form["tenPhim"];
            maNhom  = Request.Form["maNhom"];
            //maNhom = maNhom.ToUpper();
            tenPhim = LoaiBoKyTu.bestLower(tenPhim);

            if (string.IsNullOrEmpty(tenPhim))
            {
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ");
                return("Tên phim không hợp lệ");
            }
            if (string.IsNullOrEmpty(maNhom) || !db.Nhom.Any(n => n.MaNhom == maNhom))
            {
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã nhóm không hợp lệ");
                return("Mã nhóm không hợp lệ");
            }


            if (file.Length > TenMegaBytes)
            {
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Dung lượng file vượt quá 1 MB!");
                return("Dung lượng file vượt quá 1 MB!");
            }
            if (file.ContentType == "image/png" || file.ContentType == "image/jpeg" || file.ContentType == "image/jpg" || file.ContentType == "image/gif")
            {
                try
                {
                    //tenPhim = LoaiBoKyTu.bestLower(file.FileName);
                    //Check khoa học
                    //var kh = db.Phim.Where(n => n.BiDanh.Contains(tenPhim));
                    //if (kh.Count() == 0)
                    //{
                    //    return await tbl.TBLoi(ThongBaoLoi.Loi500, "Phim không tồn tại không thể upload file");
                    //}

                    var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/hinhanh", tenPhim + "_" + LoaiBoKyTu.bestLower(maNhom) + "." + file.FileName.Split('.')[file.FileName.Split('.').Length - 1]);
                    var stream = new FileStream(path, FileMode.Create);
                    file.CopyTo(stream);
                    return("");
                }
                catch
                {
                    //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Upload file không thành công!");
                    return("Upload file không thành công!");
                }
            }
            else
            {
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Định dạng file không hợp lệ!");
                return("Định dạng file không hợp lệ!");
            }
        }
Exemple #4
0
        public async Task <dynamic> suaSanPhamLoai(SanPhamLoai sanPhamLoai)
        {
            SanPhamLoai sanPhamCN;

            using (var connection = new SqlConnection(connectionstr))
            {
                var p = new DynamicParameters();
                p.Add("@ID", sanPhamLoai.MaSP);
                p.Add("TABLE", "SANPHAMLOAI");
                sanPhamCN = connection.QuerySingleOrDefault <SanPhamLoai>("SP_GETDETAILBYID", p, commandType: CommandType.StoredProcedure);
            }
            if (sanPhamCN == null)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Product ID not exist!");

                return(response.Content);
            }
            try
            {
                string hinhAnh = LoaiBoKyTu.bestLower(sanPhamLoai.TenSP) + "-" + LoaiBoKyTu.bestLower(sanPhamLoai.MaSP) + "." + sanPhamLoai.HinhAnh.Split('.')[sanPhamLoai.HinhAnh.Split('.').Length - 1];
                hinhAnh = hostImage + hinhAnh;
                using (var connection = new SqlConnection(connectionstr))
                {
                    var p = new DynamicParameters();
                    p.Add("@MaSP", sanPhamLoai.MaSP);
                    p.Add("@TenSP", sanPhamLoai.TenSP);
                    p.Add("@DonGia", sanPhamLoai.DonGia);
                    p.Add("@SoLuongTon", sanPhamLoai.SoLuongTon);
                    p.Add("@HinhAnh", hinhAnh);
                    p.Add("@MoTa", sanPhamLoai.MoTa);
                    p.Add("@LuotXem", sanPhamLoai.LuotXem);
                    p.Add("@LuotBC", sanPhamLoai.LuotBC);
                    p.Add("@SoLanMua", sanPhamLoai.SoLanMua);
                    p.Add("@MaNCC", sanPhamLoai.MaNCC);
                    p.Add("@MaNSX", sanPhamLoai.MaNSX);
                    p.Add("@MaLoaiSP", sanPhamLoai.MaLoaiSP);
                    p.Add("@TrangThai", sanPhamLoai.TrangThai);
                    p.Add("@SPMoi", sanPhamLoai.SPMoi);

                    connection.Query <SanPhamLoai>("SANPHAMLOAI_UPDATE", p, commandType: CommandType.StoredProcedure);
                }
            }
            catch (Exception ex)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "UnSuitable Value!");

                return(response.Content);
            }
            return(sanPhamLoai);
        }
        public async Task <ActionResult> ThemNguoiDung(NguoiDungVM nd)
        {
            nd.MaNhom = nd.MaNhom.ToUpper();
            bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung);

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

                return(response);
            }
            bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom);

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

                return(response);
            }
            bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email);

            if (ckEmail)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!");

                return(response);
            }
            var nguoiDung = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan);

            if (nguoiDung != null)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản đã tồn tại!");

                return(response);
            }
            try
            {
                NguoiDung ndInsert = Mapper.Map <NguoiDungVM, NguoiDung>(nd);
                ndInsert.BiDanh = LoaiBoKyTu.bestLower(ndInsert.HoTen);
                db.NguoiDung.Add(ndInsert);
                db.SaveChanges();
                return(Ok(nd));
            }
            catch (Exception ex)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!");

                return(response);
            }
        }
Exemple #6
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));
        }
Exemple #7
0
        public async Task <ResponseEntity> LayDanhSachPhimPhanTrang(string maNhom = "GP01", string tenPhim = "", int soTrang = 1, int soPhanTuTrenTrang = 10)
        {
            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.OK, MessageConstant.MESSAGE_NOTFOUND_GROUP, MessageConstant.MESSAGE_SUCCESS_200));
            }
            tenPhim = LoaiBoKyTu.bestLower(tenPhim);
            IEnumerable <PhimVM> lstResult = db.Phim.Where(n => n.BiDanh.Contains(tenPhim) && n.MaNhom == maNhom && n.DaXoa != true).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
            });

            PaginationSet <PhimVM> result = new PaginationSet <PhimVM>();

            result.CurrentPage = soTrang;
            result.TotalPages  = (lstResult.Count() / soPhanTuTrenTrang) + 1;
            result.Items       = lstResult.Skip((soTrang - 1) * soPhanTuTrenTrang).Take(soPhanTuTrenTrang);
            result.TotalCount  = lstResult.Count();
            return(new ResponseEntity(StatusCodeConstants.OK, result, MessageConstant.MESSAGE_SUCCESS_200));
        }
Exemple #8
0
        public async Task <ResponseEntity> LayDanhSachPhim(string maNhom = "GP01", string tenPhim = "")
        {
            try
            {
                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.OK, response, MessageConstant.MESSAGE_SUCCESS_200));
                }
                tenPhim = LoaiBoKyTu.bestLower(tenPhim);
                IEnumerable <PhimVM> lstResult = db.Phim.Where(n => n.BiDanh.Contains(tenPhim) && n.MaNhom == maNhom && n.DaXoa != true).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, DangChieu = n.DangChieu, Hot = n.Hot, SapChieu = n.SapChieu
                });

                return(new ResponseEntity(StatusCodeConstants.OK, lstResult, MessageConstant.MESSAGE_SUCCESS_200));
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.OK, "Không tìm thấy phim !", MessageConstant.MESSAGE_SUCCESS_200));
            }
        }
        public async Task <IActionResult> UploadHinhAnh()
        {
            IFormFile file  = Request.Form.Files[0];
            string    tenSP = Request.Form["tenSP"];
            string    maSP  = Request.Form["maSP"];

            tenSP = LoaiBoKyTu.bestLower(tenSP);
            maSP  = LoaiBoKyTu.bestLower(maSP);

            if (file.Length > TenMegaBytes)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dung lượng file vượt quá 1 MB!");

                return(Ok("Dung lượng file vượt quá 1 MB!"));
            }
            if (file.ContentType == "image/png" || file.ContentType == "image/jpeg" || file.ContentType == "image/jpg" || file.ContentType == "image/gif")
            {
                try
                {
                    var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", tenSP + "-" + maSP + "." + file.FileName.Split('.')[file.FileName.Split('.').Length - 1]);
                    var stream = new FileStream(path, FileMode.Create);
                    file.CopyTo(stream);
                    return(Ok("success"));
                }
                catch
                {
                    var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Upload file không thành công!");

                    return(Ok("Upload file fail!"));
                }
            }
            else
            {
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Định dạng file không hợp lệ!");
                return(Ok("File Fomat is unsuitable !"));
            }
        }
        public async Task <ResponseEntity> CapNhatThongTinNguoiDung(NguoiDungVM nd)
        {
            nd.MaNhom = nd.MaNhom.ToUpper();
            bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung);

            if (!ckbLoaiND)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Loại người dùng không hợp lệ!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!");
                //return response;
            }
            bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom);

            if (!ckNhom)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Nhóm người dùng không hợp lệ!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!");
                //return response;
            }
            bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email && n.TaiKhoan != nd.TaiKhoan);

            if (ckEmail)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Email đã tồn tại!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!");
                //return response;
            }
            NguoiDung nguoiDungCapNhat = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan);

            if (nguoiDungCapNhat == null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tài khoản đã tồn tại!", MessageConstant.ERROR));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản không tồn tại!");
                //return response;
            }
            try
            {
                if (nd.MatKhau == "")
                {
                    nd.MatKhau = nguoiDungCapNhat.MatKhau;
                }

                //nguoiDungCapNhat.TaiKhoan = ndUpdate.TaiKhoan;
                nguoiDungCapNhat.HoTen           = nd.HoTen;
                nguoiDungCapNhat.MatKhau         = nd.MatKhau;
                nguoiDungCapNhat.BiDanh          = LoaiBoKyTu.bestLower(nd.HoTen);
                nguoiDungCapNhat.SoDt            = nd.SoDt;
                nguoiDungCapNhat.MaLoaiNguoiDung = nd.MaLoaiNguoiDung;
                nguoiDungCapNhat.Email           = nd.Email;
                //nguoiDungCapNhat.MaNhom = ndUpdate.MaNhom;

                db.SaveChanges();
                var result = new ThongTinTaiKhoanVM {
                    TaiKhoan = nguoiDungCapNhat.TaiKhoan, MatKhau = nguoiDungCapNhat.MatKhau, HoTen = nguoiDungCapNhat.HoTen, Email = nguoiDungCapNhat.Email, SoDT = nguoiDungCapNhat.SoDt, MaNhom = nguoiDungCapNhat.MaNhom, LoaiNguoiDung = nguoiDungCapNhat.MaLoaiNguoiDungNavigation.TenLoai
                };

                return(new ResponseEntity(StatusCodeConstants.OK, result, MessageConstant.MESSAGE_SUCCESS_200));
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.OK, "Dữ liệu không hợp lệ!", MessageConstant.MESSAGE_SUCCESS_200));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!");
                //return response;
            }
        }
        public async Task <ActionResult> CapNhatThongTinNguoiDung(NguoiDungVM nd)
        {
            nd.MaNhom = nd.MaNhom.ToUpper();
            bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung);

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

                return(response);
            }
            bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom);

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

                return(response);
            }
            bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email && n.TaiKhoan != nd.TaiKhoan);

            if (ckEmail)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!");

                return(response);
            }
            NguoiDung nguoiDungCapNhat = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan);

            if (nguoiDungCapNhat == null)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản không tồn tại!");

                return(response);
            }
            try
            {
                if (nd.MatKhau == "")
                {
                    nd.MatKhau = nguoiDungCapNhat.MatKhau;
                }

                //nguoiDungCapNhat.TaiKhoan = ndUpdate.TaiKhoan;
                nguoiDungCapNhat.HoTen           = nd.HoTen;
                nguoiDungCapNhat.MatKhau         = nd.MatKhau;
                nguoiDungCapNhat.BiDanh          = LoaiBoKyTu.bestLower(nd.HoTen);
                nguoiDungCapNhat.SoDt            = nd.SoDt;
                nguoiDungCapNhat.MaLoaiNguoiDung = nd.MaLoaiNguoiDung;
                nguoiDungCapNhat.Email           = nd.Email;
                //nguoiDungCapNhat.MaNhom = ndUpdate.MaNhom;

                db.SaveChanges();
                return(Ok(new ThongTinTaiKhoanVM {
                    TaiKhoan = nguoiDungCapNhat.TaiKhoan, MatKhau = nguoiDungCapNhat.MatKhau, HoTen = nguoiDungCapNhat.HoTen, Email = nguoiDungCapNhat.Email, SoDT = nguoiDungCapNhat.SoDt, MaNhom = nguoiDungCapNhat.MaNhom, LoaiNguoiDung = nguoiDungCapNhat.MaLoaiNguoiDungNavigation.TenLoai
                }));
            }
            catch (Exception ex)
            {
                var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!");

                return(response);
            }
        }
Exemple #12
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!");
            }
        }
        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!");
            }
        }
        public async Task <object> ThemPhim(PhimInsert phim)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                string tenPhim = LoaiBoKyTu.bestLower(phim.TenPhim);
                if (string.IsNullOrEmpty(tenPhim))
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tên phim không hợp lệ!"));
                }
                var p = connection.Query("SELECT TenPhim FROM dbo.PHIM WHERE BiDanh = '" + tenPhim + "'", commandType: CommandType.Text);

                if (p.Count() > 1)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Tên phim đã tồn tại!"));
                }
                phim.BiDanh = LoaiBoKyTu.bestLower(phim.TenPhim);
                Phim modelInsert = new Phim();
                modelInsert.TenPhim = phim.TenPhim;
                modelInsert.HinhAnh = phim.HinhAnh;
                //DateTime temp;
                //try
                //{
                //    try
                //    {
                //        temp = DateTimes.ConvertDate(phim.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 !");
                //}
                //try
                //{
                //    modelInsert.NgayKhoiChieu = DateTimes.ConvertDate(phim.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 !");
                //}

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

                    return(response);
                }
                //Kiểm tra link trailer
                modelInsert.Trailer = phim.Trailer;
                string newString = "";
                if (!string.IsNullOrEmpty(modelInsert.Trailer))
                {
                    newString = modelInsert.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]"));
                    }
                }

                var param = new DynamicParameters();
                param.Add("@TENPHIM", modelInsert.TenPhim);
                param.Add("@BIDANH", LoaiBoKyTu.bestLower(phim.TenPhim));
                param.Add("@TRAILER", modelInsert.Trailer);
                param.Add("@HINHANH", hostName + modelInsert.HinhAnh);
                param.Add("@MOTA", phim.MoTa);
                param.Add("@NGAYKHOICHIEU", phim.NgayKhoiChieu);
                param.Add("@DANHGIA", phim.DanhGia);
                param.Add("@DIENVIEN", phim.DienVien);
                param.Add("@DAODIEN", phim.DaoDien);
                param.Add("@DOTUOI", phim.DoTuoi);
                param.Add("@DAXOA", phim.DaXoa);
                param.Add("@KHOICHIEU", phim.KhoiChieu);
                param.Add("@SAPCHIEU", phim.SapChieu);

                connection.Query <Phim>("PHIM_INSERT", param, commandType: CommandType.StoredProcedure);

                return("Thêm phim thành công!");
            }
            //return newString.Split('♥').Length + " " + newString;
        }
Exemple #17
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ệ!");
            }
        }