Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Ten_Phong,Da_xoa,RapPhim_ID")] PhongChieuModel phongChieuModel)
        {
            if (id != phongChieuModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phongChieuModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhongChieuModelExists(phongChieuModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RapPhim_ID"] = new SelectList(_context.Set <RapPhimModel>(), "ID", "ID", phongChieuModel.RapPhim_ID);
            return(View(phongChieuModel));
        }
        public async Task <bool> Edit(int id, [Bind("ID,Ten_Phong,Da_xoa,RapPhim_ID")] PhongChieuModel phongChieuModel)
        {
            if (id != phongChieuModel.ID)
            {
                return(false);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phongChieuModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException err)
                {
                    if (!PhongChieuModelExists(phongChieuModel.ID))
                    {
                        return(false);
                    }
                    Console.WriteLine(err);
                    return(false);
                }

                return(true);
            }
            ViewData["RapPhim_ID"] = new SelectList(_context.Set <RapPhimModel>(), "ID", "ID", phongChieuModel.RapPhim_ID);
            return(false);
        }
        public async Task <ActionResult <PhongChieuModel> > PostPhongChieuModel(PhongChieuModel phongChieuModel)
        {
            _context.PhongChieuModel.Add(phongChieuModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPhongChieuModel", new { id = phongChieuModel.ID }, phongChieuModel));
        }
        public async Task <IActionResult> PutPhongChieuModel(int id, PhongChieuModel phongChieuModel)
        {
            if (id != phongChieuModel.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        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));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("ID,Ten_Phong,Da_xoa,RapPhim_ID")] PhongChieuModel phongChieuModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(phongChieuModel);
                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 = phongChieuModel.ID;
                    _context.GheModel.Add(ghe);
                    await _context.SaveChangesAsync();
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RapPhim_ID"] = new SelectList(_context.Set <RapPhimModel>(), "ID", "ID", phongChieuModel.RapPhim_ID);
            return(View(phongChieuModel));
        }