public ResponseInfo UpdateLoaiTruyen(LoaiTruyen data, int id)
        {
            ResponseInfo response = new ResponseInfo();
            var          kt       = Convert.ToInt64(new GetPermission().GetQuyen("CATEGORY_UPD")) & Convert.ToInt64(Common.Common.GetTongQuyen());

            if (kt != 0)
            {
                try
                {
                    response = new QuanLyLoaiTruyenModel().UpadateLoaiTruyen(data, id);
                }
                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;
                }
            }
            else
            {
                var errorMsg = new GetErrorMsg().GetMsg((int)MessageEnum.MsgNO.BanKhongDuQuyen);
                response.TypeMsgError = errorMsg.Type;
                response.MsgError     = errorMsg.Msg;
            }

            return(response);
        }
        /// <summary>
        /// Thêm loại truyện
        /// Author       :   HoangNM - 10/03/2019 - create
        /// </summary>
        /// <param name="ids">Danh sách id của các loại truyện sẽ xóa</param>
        /// <returns>Trả về các thông tin khi cập nhật loại truyện, Excetion nếu có lỗi</returns>
        public ResponseInfo ThemLoaiTruyen(LoaiTruyen loaiTruyen)
        {
            DbContextTransaction transaction = context.Database.BeginTransaction();

            try
            {
                ResponseInfo response = new ResponseInfo();

                int id = context.LoaiTruyens.Count() == 0 ? 1 : context.LoaiTruyens.Max(x => x.Id) + 1;
                context.LoaiTruyens.Add(new TbLoaiTruyen
                {
                    TenTheLoai = loaiTruyen.TenLoaiTruyen,
                    Mota       = loaiTruyen.MoTa
                });
                context.SaveChanges();
                response.ThongTinBoSung1 = 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;
            }
        }
        /// <summary>
        /// Cập nhật thông tin loại truyện
        /// Author       :   HoangNM - 10/03/2019 - create
        /// </summary>
        /// <param name="loaiTruyen">thông tin về loại truyện muốn thay đổi</param>
        /// <returns>Trả về các thông tin khi cập nhật loại truyện, Excetion nếu có lỗi</returns>
        public ResponseInfo UpadateLoaiTruyen(LoaiTruyen loaiTruyen, int id)
        {
            DbContextTransaction transaction = context.Database.BeginTransaction();
            ResponseInfo         response    = new ResponseInfo();

            try
            {
                context.LoaiTruyens.Where(x => x.Id == id && !x.DelFlag)
                .Update(x => new TbLoaiTruyen
                {
                    TenTheLoai = loaiTruyen.TenLoaiTruyen,
                    Mota       = loaiTruyen.MoTa
                });
                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;
            }
        }
 /// <summary>
 /// Lấy thông tin 1 loại truyện
 /// Author       :   HoangNM - 10/03/2019 - create
 /// </summary>
 /// <returns>Danh sách các loại truyện. Exception nếu có lỗi</returns>
 public LoaiTruyen LoadLoaiTruyen(int id)
 {
     try
     {
         LoaiTruyen   loaiTruyen   = new LoaiTruyen();
         TbLoaiTruyen tbLoaiTruyen = context.LoaiTruyens.FirstOrDefault(x => x.Id == id && !x.DelFlag);
         if (tbLoaiTruyen != null)
         {
             loaiTruyen.Id            = tbLoaiTruyen.Id;
             loaiTruyen.TenLoaiTruyen = tbLoaiTruyen.TenTheLoai;
             loaiTruyen.MoTa          = tbLoaiTruyen.Mota;
         }
         return(loaiTruyen);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #5
0
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_maloai.Text))
            {
                Form1.Default.ShowMessageWarning("Bạn phải nhập vào mã loại truyện.");
                txt_maloai.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_loaitruyen.Text))
            {
                Form1.Default.ShowMessageWarning("Bạn phải nhập vào tên loại truyện.");
                txt_loaitruyen.Focus();
                return;
            }
            if (Convert.ToInt32(ExecSQL.ExecQuerySacalar($"SELECT COUNT(*) FROM dbo.tbl_loaitruyen WHERE maloai='{txt_maloai.Text}'")) > 0)
            {
                Form1.Default.ShowMessageWarning("Mã loại truyện này đã tồn tại.");
                txt_maloai.Text = "";
                txt_maloai.Focus();
                return;
            }
            var loaitruyen = new LoaiTruyen {
                maloai = txt_maloai.Text, loaitruyen = txt_loaitruyen.Text, nguoitd = ComicPro.StrTenDangNhap.ToUpper()
            };

            ExecSQL.Insert(loaitruyen);
            XoaText();
            //Gửi dữ liệu
            var message = new MessageBroker
            {
                data = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                task = "loaitruyen"
            };

            message.Publish();
        }