コード例 #1
0
        /// <summary>
        /// Thêm phân quyền
        /// Author       :   HoangNM - 16/04/2019 - create
        /// </summary>
        /// <param name="phanQuyen">phân quyền sẽ thêm</param>
        /// <returns>Trả về các thông tin khi thêm quyền vào db, Excetion nếu có lỗi</returns>
        public ResponseInfo ThemPhanQuyen(NewPhanQuyen phanQuyen)
        {
            DbContextTransaction transaction = context.Database.BeginTransaction();

            try
            {
                ResponseInfo response = new ResponseInfo();

                int     id        = context.PhanQuyens.Count() == 0 ? 1 : context.PhanQuyens.Max(x => x.Id) + 1;
                decimal TongQuyen = 0;
                foreach (int i in phanQuyen.Id_QuyenList)
                {
                    TongQuyen += context.Quyens.FirstOrDefault(x => x.Id == i && !x.DelFlag).BitQuyen;
                }
                context.PhanQuyens.Add(new TblPhanQuyen
                {
                    TenVaiTro = phanQuyen.TenVaiTro,
                    TongQuyen = TongQuyen
                });
                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;
            }
        }
コード例 #2
0
        /// <summary>
        /// Cập nhật thông tin phân quyền
        /// Author       :   HoangNM - 16/04/2019 - create
        /// </summary>
        /// <param name="phanQuyen">thông tin về phân quyền muốn thay đổi</param>
        /// <param name="id">là id của quyền muốn cập nhật</param>
        /// <returns>Trả về các thông tin khi cập nhật quyền, Excetion nếu có lỗi</returns>
        public ResponseInfo UpadatePhanQuyen(NewPhanQuyen phanQuyen, int id)
        {
            DbContextTransaction transaction = context.Database.BeginTransaction();
            ResponseInfo         response    = new ResponseInfo();

            try
            {
                decimal TongQuyen = 0;
                foreach (int i in phanQuyen.Id_QuyenList)
                {
                    TongQuyen += context.Quyens.FirstOrDefault(x => x.Id == i && !x.DelFlag).BitQuyen;
                }
                context.PhanQuyens.Where(x => x.Id == id && !x.DelFlag)
                .Update(x => new TblPhanQuyen
                {
                    TenVaiTro = phanQuyen.TenVaiTro,
                    TongQuyen = TongQuyen
                });
                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;
            }
        }
コード例 #3
0
        public ResponseInfo UpdatePhanQuyen(NewPhanQuyen data, int id)
        {
            ResponseInfo response = new ResponseInfo();

            try
            {
                response = new QuanLyPhanQuyenModel().UpadatePhanQuyen(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;
            }
            return(response);
        }