Beispiel #1
0
 /// <summary>
 /// Lấy thông tin 1 nhóm dịch
 /// Author       :   HoangNM - 18/03/2019 - create
 /// </summary>
 /// <returns>lấy ra nhóm dịch theo id. Exception nếu có lỗi</returns>
 public NhomDich LoadNhomDich(int id)
 {
     try
     {
         NhomDich    nhomDich    = new NhomDich();
         TblNhomDich tblNhomDich = context.NhomDiches.FirstOrDefault(x => x.Id == id && !x.DelFlag);
         if (tblNhomDich != null)
         {
             nhomDich.Id          = tblNhomDich.Id;
             nhomDich.TenNhomDich = tblNhomDich.TenNhomDich;
             nhomDich.MoTa        = tblNhomDich.MoTa;
             nhomDich.Logo        = tblNhomDich.Logo;
         }
         return(nhomDich);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Xóa các nhóm dịch trong DB.
        /// Author       :   HoangNM - 18/03/2019 - create
        /// </summary>
        /// <param name="ids">Danh sách id của các nhóm dịch sẽ xóa</param>
        /// <returns>True nếu xóa thành công, False nếu không còn nhóm dịch được hiển thị trên trang chủ, Excetion nếu có lỗi</returns>
        public bool DeleteNhomDich(int id)
        {
            DbContextTransaction transaction = context.Database.BeginTransaction();

            try
            {
                bool result = true;
                if (context.NhomDiches.FirstOrDefault(x => x.Id == id && !x.DelFlag) != null)
                {
                    TblNhomDich nhomDich = context.NhomDiches.FirstOrDefault(x => x.Id == id && !x.DelFlag);
                    nhomDich.DelFlag = true;
                    context.Truyens.Where(x => x.Id_Nhom == id && !x.DelFlag).Update(x => new TblTruyen
                    {
                        DelFlag = true
                    });
                    context.Chuongs.Where(x => x.Truyen.Id_Nhom == id && !x.DelFlag).Update(x => new TblChuong
                    {
                        DelFlag = true
                    });
                    context.TaiKhoans.Where(x => x.Id_NhomDich == id && !x.DelFlag).Update(x => new TblTaiKhoan
                    {
                        Id_NhomDich = 1
                    });
                    context.SaveChanges();
                }
                else
                {
                    result = false;
                }
                transaction.Commit();
                return(result);
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
        }