Пример #1
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ệ!");
            }
        }
Пример #2
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!");
            }
        }