Beispiel #1
0
        public ChuongTruyen Laychuongtruoc(int maproject, int machuong)
        {
            var listchuongtruyen = data.ChuongTruyens.Where(m => m.MaProject == maproject).OrderBy(m => m.ThuTuChuong).ToList();
            var chuongtruyen     = new ChuongTruyen();

            int i = 0;

            foreach (var item in listchuongtruyen)
            {
                if (item.MaChuongTruyen == machuong)
                {
                    if (i == 0)
                    {
                        break;
                    }
                    else
                    {
                        chuongtruyen = listchuongtruyen[i - 1];
                        return(chuongtruyen);
                    }
                }
                i++;
            }
            return(null);
        }
Beispiel #2
0
        public int Update(int machuongtruyen, string tenchuong, int thutuchuong)
        {
            ChuongTruyen chuong = data.ChuongTruyens.SingleOrDefault(n => n.MaChuongTruyen == machuongtruyen);

            chuong.TenChuongTruyen = tenchuong;
            chuong.ThoiGianCapNhat = DateTime.Now;
            chuong.ThuTuChuong     = thutuchuong;

            data.SaveChanges();
            return(chuong.MaChuongTruyen);
        }
Beispiel #3
0
        public ChuongTruyen Add(int maproject, string tenchuong, int thutu)
        {
            ChuongTruyen chuong = new ChuongTruyen();

            chuong.MaProject       = maproject;
            chuong.LuotXem         = 0;
            chuong.DaXoa           = false;
            chuong.TenChuongTruyen = tenchuong;
            chuong.ThoiGianCapNhat = DateTime.Now;
            chuong.ThuTuChuong     = thutu;
            return(chuong);
        }
        public ActionResult TaoMoi(int id, ChuongTruyenModel chuongtruyen, HttpPostedFileBase[] AnhTrang)
        {
            NguoiDung       nguoi         = (NguoiDung)Session["TaiKhoan"];
            DaoChuongTruyen chuongtruyen1 = new DaoChuongTruyen();

            ViewBag.LoaiTrang = chuongtruyen1.GetLoaiTrang();
            if (ModelState.IsValid)
            {
                int             thutu     = 0;
                DaoChuongTruyen daochuong = new DaoChuongTruyen();
                ChuongTruyen    chuong    = new ChuongTruyen();
                chuong = daochuong.Add(id, chuongtruyen.TenChuong, chuongtruyen.ThutuChuong);
                var result = daochuong.Insert(chuong);
                if (result > 0)
                {
                    string   ThuTuTrangs  = Request.Form["ThuTuTrang"];
                    string   TenTrangs    = Request.Form["TenTrang"];
                    string[] DsThuTuTrang = ThuTuTrangs.Split(new char[] { ',' });

                    string[] DsTenTrangTrang = TenTrangs.Split(new char[] { ',' });
                    for (int i = 0; i < AnhTrang.Length; i++)
                    {
                        var file1 = Path.GetFileName(AnhTrang[i].FileName);
                        var path  = Path.Combine(Server.MapPath("~/Truyen"), file1);
                        AnhTrang[i].SaveAs(path);
                        TrangTruyen trang = new TrangTruyen();
                        trang.MaChuongTruyen = result;
                        trang.MaLoaiTrang    = int.Parse(Request.Form["MaLoaiTrang"]);
                        trang.MaNguoiDung    = nguoi.MaNguoiDung;
                        trang.ThuTu          = int.Parse(DsThuTuTrang[i]);
                        trang.UrlAnh         = file1;
                        trang.DaXoa          = false;
                        trang.TenTrang       = DsTenTrangTrang[i];
                        data.TrangTruyens.Add(trang);
                        data.SaveChanges();
                        thutu += 1;
                    }
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm chương mới thất bại");
                }
            }
            else
            {
                ModelState.AddModelError("", "Yêu cầu Nhập đủ thông tin");
            }

            return(RedirectToAction("Index", "User"));
        }
Beispiel #5
0
        /// <summary>
        /// Lấy thông tin 1 truyện theo id
        /// Author       :   HoangNM - 01/04/2019 - create
        /// </summary>
        /// <returns>lấy ra truyện theo id. Exception nếu có lỗi</returns>
        public ChuongTruyen LoadTruyen(int id)
        {
            try
            {
                ChuongTruyen chuongTruyen = new ChuongTruyen();
                chuongTruyen = context.Truyens.Where(x => x.Id == id && !x.DelFlag).Select(x => new ChuongTruyen
                {
                    Id             = x.Id,
                    TenTruyen      = x.TenTruyen,
                    TenKhac        = x.TenKhac,
                    Id_TrangThai   = x.Id_TrangThai,
                    TrangThai      = x.TrangThaiTruyen.TenTrangThai,
                    Id_ChuKy       = x.Id_ChuKy,
                    DanhSachTacGia = x.LuuTacGias.Where(y => !y.DelFlag).Select(y => new TacGia
                    {
                        Id        = y.Id_TacGia,
                        TenTacGia = y.TacGia.TenTacGia
                    }).ToList(),
                    AnhBia          = x.AnhBia,
                    AnhDaiDien      = x.AnhDaiDien,
                    DanhSachTheLoai = x.LuuLoaiTruyens.Where(y => !y.DelFlag).Select(y => new TheLoai
                    {
                        Id         = y.LoaiTruyen.Id,
                        TenTheLoai = y.LoaiTruyen.TenTheLoai,
                        MoTa       = y.LoaiTruyen.Mota
                    }).ToList(),
                    NamPhatHanh = x.NamPhatHanh,
                    MoTa        = x.MoTa,
                    TenChuKy    = x.ChuKyPhatHanh.TenChuKy,
                    Id_Nhom     = x.Id_Nhom,
                    TenNhom     = x.NhomDich.TenNhomDich,
                    listChuong  = x.Chuongs.Select(y => new Chuong
                    {
                        IdChuong  = y.Id,
                        TenChuong = y.TenChuong,
                        soThuTu   = y.SoThuTu,
                        luotXem   = y.LuotXem,
                        ngayTao   = y.NgayTao
                    }).ToList()
                }).FirstOrDefault();


                return(chuongTruyen);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #6
0
        public ChuongTruyen LayChuongSauTrongListBanDich(int machuong, List <ChuongTruyen> chuong)
        {
            var chuongtruyen = new ChuongTruyen();
            var count        = chuong.Count();
            int i            = 0;

            foreach (var item in chuong)
            {
                if (item.MaChuongTruyen == machuong)
                {
                    if (i != count - 1)
                    {
                        chuongtruyen = chuong[i + 1];
                        return(chuongtruyen);
                    }
                }
                i++;
            }
            return(null);
        }
Beispiel #7
0
        public ChuongTruyen Laychuongsau(int maproject, int machuong)
        {
            var listchuongtruyen = data.ChuongTruyens.Where(m => m.MaProject == maproject).OrderBy(m => m.ThuTuChuong).ToList();
            var chuongtruyen     = new ChuongTruyen();
            var count            = listchuongtruyen.Count();
            int i = 0;

            foreach (var item in listchuongtruyen)
            {
                if (item.MaChuongTruyen == machuong)
                {
                    if (i != count - 1)
                    {
                        chuongtruyen = listchuongtruyen[i + 1];
                        return(chuongtruyen);
                    }
                }
                i++;
            }
            return(null);
        }
Beispiel #8
0
        public ChuongTruyen LayChuongTruocTrongListBanDich(int machuong, List <ChuongTruyen> chuong)
        {
            var chuongtruyen = new ChuongTruyen();

            int i = 0;

            foreach (var item in chuong)
            {
                if (item.MaChuongTruyen == machuong)
                {
                    if (i == 0)
                    {
                        break;
                    }
                    else
                    {
                        chuongtruyen = chuong[i - 1];
                        return(chuongtruyen);
                    }
                }
                i++;
            }
            return(null);
        }
Beispiel #9
0
 //Thêm chương//
 //Ryu//
 public int Insert(ChuongTruyen chuong)
 {
     data.ChuongTruyens.Add(chuong);
     data.SaveChanges();
     return(chuong.MaChuongTruyen);
 }