public async Task <ActionResult> DatVe(DanhSachVeDat DanhSachVe)
        {
            var nd = db.NguoiDung.Where(n => n.TaiKhoan == DanhSachVe.TaiKhoanNguoiDung);

            if (nd.Count() == 0)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản người dùng không tồn tại!"));
            }
            if (DanhSachVe == null)
            {
                return(Ok("Danh sách vé rỗng!"));
            }

            foreach (var ve in DanhSachVe.DanhSachVe)
            {
                DatVe dv = new DatVe();
                dv.NgayDat           = DateTime.Now;
                dv.MaGhe             = ve.MaGhe;
                dv.GiaVe             = ve.GiaVe;
                dv.TaiKhoanNguoiDung = DanhSachVe.TaiKhoanNguoiDung;
                dv.MaLichChieu       = DanhSachVe.MaLichChieu;
                db.DatVe.Add(dv);
            }
            db.SaveChanges();
            return(Ok("Đặt vé thành công!"));
        }
        public async Task <ResponseEntity> DangKy(NguoiDung_VM nd)
        {
            //nd.MaNhom = nd.MaNhom.ToUpper();
            //bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom);
            //if (!ckNhom)
            //{
            //    return new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Nhóm người dùng không hợp lệ!", MessageConstant.BAD_REQUEST);

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

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

                //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.BAD_REQUEST, "Tài khoản đã tồn tại!", MessageConstant.BAD_REQUEST));

                //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản đã tồn tại!");
                //return response;
            }
            try
            {
                NguoiDung ndInsert = Mapper.Map <NguoiDung_VM, NguoiDung>(nd);
                ndInsert.MaLoaiNguoiDung = LoaiND.KhachHang;
                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 <ActionResult> DangKy(NguoiDungVM nd)
        {
            nd.MaNhom = nd.MaNhom.ToUpper();
            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.MaLoaiNguoiDung = LoaiND.KhachHang;
                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);
            }
        }
        public async Task <ResponseEntity> DatVe(DanhSachVeDat DanhSachVe)
        {
            var accessToken = Request.Headers[HeaderNames.Authorization];

            userToken usToken = commonService.getUserByToken(accessToken).Result;

            if (usToken == null)
            {
                return(new ResponseEntity(StatusCodeConstants.AUTHORIZATION, "Token đã hết hạn bạn hãy đăng nhập lại!", MessageConstant.MESSAGE_ERROR_401));
            }

            var nd = db.NguoiDung.Where(n => n.TaiKhoan == usToken.taiKhoan);

            if (nd.Count() == 0)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tài khoản người dùng không tồn tại!", MessageConstant.MESSAGE_ERROR_500));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản người dùng không tồn tại!");
            }
            if (DanhSachVe == null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Danh sách vé rỗng!", MessageConstant.MESSAGE_ERROR_500));

                //return Ok("Danh sách vé rỗng!");
            }

            foreach (var ve in DanhSachVe.DanhSachVe)
            {
                DatVe dv = new DatVe();
                dv.NgayDat           = DateTime.Now;
                dv.MaGhe             = ve.MaGhe;
                dv.GiaVe             = ve.GiaVe;
                dv.TaiKhoanNguoiDung = usToken.taiKhoan;
                dv.MaLichChieu       = DanhSachVe.MaLichChieu;
                db.DatVe.Add(dv);
            }
            db.SaveChanges();
            return(new ResponseEntity(StatusCodeConstants.OK, "Đặt vé thành công!", MessageConstant.MESSAGE_SUCCESS_200));

            //return Ok("Đặt vé thành công!");
        }
Esempio n. 5
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 <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!");
            }
        }