/// <summary> /// Thêm chương truyện /// Author : HoangNM - 04/04/2019 - create /// </summary> /// <param name="data">Dữ liệu của truyện sẽ thêm</param> /// <returns>Trả về các thông tin khi thêm chương truyện, Excetion nếu có lỗi</returns> public ResponseInfo ThemChuongTruyen(ChuongCuaTruyen chuongTruyen) { DbContextTransaction transaction = context.Database.BeginTransaction(); try { ResponseInfo response = new ResponseInfo(); chuongTruyen.Id = context.Chuongs.Count() == 0 ? 1 : context.Chuongs.Max(x => x.Id) + 1; context.Chuongs.Add(new TblChuongTruyen { Id = chuongTruyen.Id, Id_Truyen = chuongTruyen.IdTruyen, TenChuong = chuongTruyen.TenChuong, SoThuTu = chuongTruyen.SoThuTu, LinkAnh = chuongTruyen.LinkAnh, LuotXem = 0, NgayTao = DateTime.Now }); context.SaveChanges(); response.ThongTinBoSung1 = chuongTruyen.Id + ""; transaction.Commit(); var errorMsg = new GetErrorMsg().GetMsg((int)MessageEnum.MsgNO.ThemDuLieuThanhCong); response.TypeMsgError = errorMsg.Type; response.MsgError = errorMsg.Msg; return(response); } catch (Exception e) { transaction.Rollback(); throw e; } }
public ResponseInfo ThemChuongTruyen(ChuongCuaTruyen data) { ResponseInfo response = new ResponseInfo(); try { var kt = Convert.ToInt64(new GetPermission().GetQuyen("CHAPTER_CRE")) & Convert.ToInt64(Common.Common.GetTongQuyen()); if (kt != 0) { response = new QuanLyChuongTruyenModel().ThemChuongTruyen(data); } else { var errorMsg = new GetErrorMsg().GetMsg((int)MessageEnum.MsgNO.BanKhongDuQuyen); response.TypeMsgError = errorMsg.Type; response.MsgError = errorMsg.Msg; } } catch (Exception e) { response.Code = (int)ConstantsEnum.CodeResponse.ServerError; var errorMsg = new GetErrorMsg().GetMsg((int)MessageEnum.MsgNO.ServerError); response.TypeMsgError = errorMsg.Type; response.MsgError = errorMsg.Msg; response.ThongTinBoSung1 = e.Message; } return response; }
/// <summary> /// Cập nhật thông tin chương truyện /// Author : HoangNM - 14/04/2019 - create /// </summary> /// <param name="chuong">thông tin về chương truyện muốn thay đổi</param> /// <returns>Trả về các thông tin khi cập nhật chương truyện, Excetion nếu có lỗi</returns> public ResponseInfo UpadateChuongTruyen(ChuongCuaTruyen chuong, int id) { DbContextTransaction transaction = context.Database.BeginTransaction(); ResponseInfo response = new ResponseInfo(); try { var kt = Convert.ToInt64(new GetPermission().GetQuyen("CHAPTER_MAN")) & Convert.ToInt64(Common.Common.GetTongQuyen()); if (kt != 0) { context.Chuongs.Where(x => x.Id == id && !x.DelFlag) .Update(x => new TblChuongTruyen { Id_Truyen = chuong.IdTruyen, TenChuong = chuong.TenChuong, SoThuTu = chuong.SoThuTu, LinkAnh = chuong.LinkAnh }); } else { context.Chuongs.Where(x => x.Id == id && x.Truyen.Id_Nhom == Common.Common.GetAccount().IdNhom&& !x.DelFlag) .Update(x => new TblChuongTruyen { Id_Truyen = chuong.IdTruyen, TenChuong = chuong.TenChuong, SoThuTu = chuong.SoThuTu, LinkAnh = chuong.LinkAnh }); } context.SaveChanges(); response.IsSuccess = true; transaction.Commit(); var errorMsg = new GetErrorMsg().GetMsg((int)MessageEnum.MsgNO.CapNhatDuLieuThanhCong); response.TypeMsgError = errorMsg.Type; response.MsgError = errorMsg.Msg; return(response); } catch (Exception e) { response.IsSuccess = false; transaction.Rollback(); throw e; } }