public async Task <IActionResult> Edit(int id, [Bind("ID,Ten_rap,Dia_chi,Da_xoa")] RapPhimModel rapPhimModel)
        {
            if (id != rapPhimModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rapPhimModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RapPhimModelExists(rapPhimModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rapPhimModel));
        }
Esempio n. 2
0
        // GET: Admin/RapPhim
        public async Task <IActionResult> Index(int?id, string?s_name)
        {
            RapPhimModel rapPhim = null;

            ViewBag.lstCumRap = (from l in _context.tb_CumRap
                                 select l).ToList();

            ViewBag.lstCumRap_Active = (from l in _context.tb_CumRap
                                        where l.TrangThai == true
                                        select l).ToList();

            if (id != null)
            {
                rapPhim = await _context.tb_RapPhim.FirstOrDefaultAsync(m => m.Id == id);
            }
            if (s_name != null)
            {
                ViewBag.lstRapPhim = (from p in _context.tb_RapPhim
                                      where p.TenRap.IndexOf(s_name) >= 0 &&
                                      p.TrangThai == true


                                      select p).ToList();
            }
            else
            {
                ViewBag.lstRapPhim = (from p in _context.tb_RapPhim
                                      where p.TrangThai == true

                                      select p).ToList();
            }
            return(View(rapPhim));
        }
Esempio n. 3
0
        public async Task <ActionResult <RapPhimModel> > PostRapPhimModel(RapPhimModel rapPhimModel)
        {
            _context.tb_RapPhim.Add(rapPhimModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRapPhimModel", new { id = rapPhimModel.Id }, rapPhimModel));
        }
Esempio n. 4
0
        public async Task <IActionResult> PutRapPhimModel(int id, RapPhimModel rapPhimModel)
        {
            if (id != rapPhimModel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(rapPhimModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RapPhimModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TenRap,DiaChi,HinhAnh,MaCumRap,TrangThai")] RapPhimModel rapPhimModel, IFormFile ful)
        {
            rapPhimModel.TrangThai = true;
            if (id != rapPhimModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rapPhimModel);
                    if (ful != null)//Neu chon hinh cu
                    {
                        var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pic_cinema", rapPhimModel.HinhAnh);
                        System.IO.File.Delete(path); //Xoa hinh cu
                                                     //Them hinh moi
                        path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pic_cinema",
                                            rapPhimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await ful.CopyToAsync(stream);
                        }
                        rapPhimModel.HinhAnh = rapPhimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                        _context.Update(rapPhimModel);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RapPhimModelExists(rapPhimModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Success"] = "Chỉnh sửa rạp " + rapPhimModel.TenRap + " thành công! ";
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MaCumRap"] = new SelectList(_context.tb_CumRap, "Id", "TenCum", rapPhimModel.MaCumRap);
            return(View(rapPhimModel));
        }
        public async Task <IActionResult> Create([Bind("ID,Ten_rap,Dia_chi,Da_xoa")] RapPhimModel rapPhimModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rapPhimModel);
                await _context.SaveChangesAsync();

                for (int i = 0; i < 3; ++i)
                {
                    PhongChieuModel phongChieu = new PhongChieuModel();
                    phongChieu.Da_xoa     = false;
                    phongChieu.Ten_Phong  = "P" + i.ToString();
                    phongChieu.RapPhim_ID = rapPhimModel.ID;
                    _context.PhongChieuModel.Add(phongChieu);
                    await _context.SaveChangesAsync();

                    for (int j = 0; j < 90; ++j)
                    {
                        GheModel ghe = new GheModel();
                        ghe.Da_xoa  = false;
                        ghe.Da_chon = false;
                        ghe.Ten     = (char)((j / 10) + 'A') + (j % 10).ToString();
                        if ((j / 10 >= 2) &&
                            (j / 10 <= 6) &&
                            (j % 10 >= 2) &&
                            (j % 10 <= 7))
                        {
                            ghe.Loai = 1;
                        }
                        else
                        {
                            ghe.Loai = 0;
                        }

                        ghe.PhongChieu_ID = phongChieu.ID;
                        _context.GheModel.Add(ghe);
                        await _context.SaveChangesAsync();
                    }
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rapPhimModel));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Id,TenRap,DiaChi,HinhAnh,MaCumRap,TrangThai")] RapPhimModel rapPhimModel, IFormFile ful)
        {
            ViewBag.lstCumRap_Active = (from l in _context.tb_CumRap
                                        where l.TrangThai == true
                                        select l).ToList();
            rapPhimModel.TrangThai = true;
            rapPhimModel.HinhAnh   = "noimg.jpg";
            if (ModelState.IsValid)
            {
                if (ful != null)
                {
                    _context.Add(rapPhimModel);
                    await _context.SaveChangesAsync();

                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/pic_cinema",
                                            rapPhimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]);
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await ful.CopyToAsync(stream);
                    }
                    rapPhimModel.HinhAnh = rapPhimModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                    _context.Update(rapPhimModel);
                    await _context.SaveChangesAsync();

                    TempData["Success"] = "Thêm rạp " + rapPhimModel.TenRap + " thành công! ";
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    TempData["Success"] = "Thất bại!";
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["MaCumRap"] = new SelectList(_context.tb_CumRap, "Id", "TenCum", rapPhimModel.MaCumRap);
            return(View("Index"));
        }