Exemple #1
0
 public CoreResult Update(KhamBenh entity, int?userId = default(int?), bool checkPermission = false)
 {
     try
     {
         this.CreateConnection();
         this.sqlHelper.CommandType = System.Data.CommandType.StoredProcedure;
         SqlDataReader dr = this.sqlHelper.ExecuteReader("[KhamBenh_Update]", new string[] {
             "@KhamBenhID", "@patientsID", "@NgayKham", "@NgayKetThucKham",
             "@ChanDoanBD", "@BenhChinh_MaICD", "@BenhKemTheo_MaICDs",
             "@DepartmentsID", "@employeesID", "@PhuongAn",
             "@GuiKham_DepartmentsIDs", "@LoaiKham", "@ChuyenKhoa_Code",
             "@userIDUpdated"
         }, new object[] {
             entity.KhamBenhID, entity.patientsID, entity.NgayKham, entity.NgayKetThucKham,
             entity.ChanDoanBD, entity.BenhChinh_MaICD, entity.BenhKemTheo_MaICDs,
             entity.DepartmentsID, entity.employeesID, entity.PhuongAn, entity.GuiKham_DepartmentsIDs,
             entity.LoaiKham, entity.ChuyenKhoa_Code
             , entity.userIDUpdated
         });
         CoreResult returnValue = this.GetCustomMessage(dr, ActionType.Edit);
         if (returnValue != null)
         {
             return(returnValue);
         }
         else
         {
             return(this.GetResultFromSqlDataReader(dr, ActionType.Edit));
         }
     }
     catch (Exception e)
     {
         this.sqlHelper.Close();
         return(this.GetResultFromStatusCode(CoreStatusCode.Exception, ActionType.Edit, e));
     }
 }
Exemple #2
0
        public CoreResult <IQueryable <Shop> > GetAll()
        {
            var result = new CoreResult <IQueryable <Shop> >();
            var shop   = _shopRepository.GetAll().AsNoTracking();

            if (shop == null)
            {
                result.Failed("数据不存在");
                return(result);
            }
            result.Success(shop);
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 列表数据不分页
        /// </summary>
        /// <returns></returns>
        public CoreResult <IQueryable <Blog> > GetAll()
        {
            var result = new CoreResult <IQueryable <Blog> >();
            var post   = _blogRepository.GetAll().AsNoTracking();

            if (post == null)
            {
                result.Failed("数据不存在");
                return(result);
            }
            result.Success(post);
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 列表数据不分页
        /// </summary>
        /// <returns></returns>
        public CoreResult <IQueryable <Company> > GetAll()
        {
            var result  = new CoreResult <IQueryable <Company> >();
            var company = _companyRepository.GetAll().AsNoTracking();

            if (company == null)
            {
                result.Failed("数据不存在");
                return(result);
            }
            result.Success(company);
            return(result);
        }
        public CoreResult <IQueryable <Country> > GetAll()
        {
            var result       = new CoreResult <IQueryable <Country> >();
            var ExchangeRate = _countryRateRepository.GetAll().AsNoTracking();

            if (ExchangeRate == null)
            {
                result.Failed("数据不存在");
                return(result);
            }
            result.Success(ExchangeRate);
            return(result);
        }
        /// <summary>
        /// 初始化过滤器上下文
        /// </summary>
        /// <param name="filterContext"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private ActionExecutingContext InitFilterContext(ActionExecutingContext filterContext, string msg)
        {
            var result = new CoreResult()
            {
                StatusCode = 0, Message = msg
            };

            filterContext.Result = new JsonResult(result)
            {
                ContentType = "application/json",
                StatusCode  = 401,
            };
            filterContext.HttpContext.Response.StatusCode = 401;
            return(filterContext);
        }
Exemple #7
0
        public async Task <CoreResult> Update([FromBody] UpdateCompanyRequestDto dto)
        {
            CoreResult           result  = new CoreResult();
            UpdateCompanyCommand command = new UpdateCompanyCommand(dto);
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("修改成功");
            }
            else
            {
                result.Failed("修改失败");
            }
            return(result);
        }
        public async Task <CoreResult> Delete(long Id)
        {
            CoreResult        result  = new CoreResult();
            BlogDeleteCommand command = new BlogDeleteCommand(Id);
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("删除成功");
            }
            else
            {
                result.Failed("删除成功");
            }
            return(result);
        }
        public async Task <CoreResult> Update([FromBody] BlogUpdateDto dto)
        {
            CoreResult        result  = new CoreResult();
            BlogUpdateCommand command = new BlogUpdateCommand(dto.Id, dto.Name, dto.Url);
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("修改成功");
            }
            else
            {
                result.Failed("修改失败");
            }
            return(result);
        }
Exemple #10
0
        public async Task <CoreResult> Create([FromBody] CreateShopRequestDto dto)
        {
            CoreResult        result  = new CoreResult();
            CreateShopCommand command = new CreateShopCommand(dto);
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("添加成功");
            }
            else
            {
                result.Failed("添加失败");
            }
            return(result);
        }
Exemple #11
0
        public async Task <CoreResult> AsyncCountry()
        {
            CoreResult          result  = new CoreResult();
            AsyncCountryCommand command = new AsyncCountryCommand();
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("国家同步成功");
            }
            else
            {
                result.Failed("国家同步失败");
            }
            return(result);
        }
Exemple #12
0
        public async Task <CoreResult> Create([FromBody] CreateCompanyRequestDto dto)
        {
            CoreResult           result  = new CoreResult();
            CreateCompanyCommand command = new CreateCompanyCommand(dto.Name, dto.SkuPrefix, dto.AdditionalFee);
            var res = await _bus.SendCommandAsync(command);

            if (res)
            {
                result.Success("添加成功");
            }
            else
            {
                result.Failed("添加失败");
            }
            return(result);
        }
Exemple #13
0
 public CoreResult Delete(int key, int?userId = default(int?), bool checkPermission = false)
 {
     try
     {
         #region Kiểm tra quyền thao tác
         var result = this.CheckPermission(userId, checkPermission, ActionType.Delete);
         #endregion
         if (result.Item1)
         {
             var _kiemtrathanhtoan = new ThanhToanProvider().KiemTraThanhToan(key);
             if (!_kiemtrathanhtoan)
             {
                 this.CreateConnection();
                 this.sqlHelper.CommandType = CommandType.StoredProcedure;
                 SqlDataReader dr          = this.sqlHelper.ExecuteReader("[RaVien_Delete]", new string[] { "@patientsID" }, new object[] { key });
                 CoreResult    returnValue = this.GetCustomMessage(dr, ActionType.Delete);
                 if (returnValue != null)
                 {
                     return(returnValue);
                 }
                 else
                 {
                     return(this.GetResultFromSqlDataReader(dr, ActionType.Delete));
                 }
             }
             else
             {
                 //bệnh nhân đã thanh toán
                 return(new CoreResult
                 {
                     StatusCode = CoreStatusCode.Failed,
                     Message = "Bệnh nhân đã thanh toán, không được sửa ra viện."
                 });
             }
         }
         else
         {
             return(result.Item2);
         }
     }
     catch (Exception e)
     {
         this.sqlHelper.Close();
         return(this.GetResultFromStatusCode(CoreStatusCode.Exception, ActionType.Delete, e));
     }
 }
 /// <summary>
 /// 异常记录
 /// </summary>
 /// <param name="filterContext"></param>
 /// <returns></returns>
 public Task OnExceptionAsync(ExceptionContext filterContext)
 {
     try
     {
         var msg = "message:" + filterContext.Exception.Message + "。stacktrace:" + filterContext.Exception.StackTrace;
         LogHelper.Nlogger.Error(msg);
         var exceptionModel = new CoreResult <string>();
         exceptionModel.StatusCode = 0;
         exceptionModel.Message    = "接口异常!";
         exceptionModel.Ext1       = msg;
         filterContext.Result      = new OkObjectResult(exceptionModel);
         filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
         //不再throw,在此捕获获取
         filterContext.ExceptionHandled = true;
     }
     catch { }
     return(Task.CompletedTask);
 }
        public async Task <IActionResult> Index()
        {
            CoreResult coreResult = new CoreResult();

            #region ServiceDiscovery

            var serviceProvider = new ConsulServiceProvider(new Uri("http://127.0.0.1:8500"));

            var _userServiceUrl = serviceProvider.CreateServiceBuilder(builder =>
            {
                builder.ServiceName  = "UserApi";
                builder.LoadBalancer = TypeLoadBalancer.RoundRobin;
                builder.UriScheme    = Uri.UriSchemeHttp;
            }).BuildAsync("/api/user/servicesdiscovery").Result;

            #endregion

            var polly = PolicyBuilder.CreatePolly();
            polly.Execute(() => {
                try
                {
                    var form = new Dictionary <string, string>()
                    {
                        { "phone", "18650482503" }
                    };
                    var response = _httpClient.PostAsync(_userServiceUrl.ToString(), new FormUrlEncodedContent(form)).Result;
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        coreResult.Success(response.Content.ReadAsStringAsync().Result);
                    }
                    else
                    {
                        coreResult.Failed(response.Content.ReadAsStringAsync().Result);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError("在重试之后失败");
                    throw new Exception(ex.Message);
                }
            });

            return(Content(coreResult.Message));
        }
 /// <summary>
 /// 验证ViewModels
 /// </summary>
 /// <param name="filterContext"></param>
 private void ValidateViewModels(ActionExecutingContext filterContext)
 {
     if (!filterContext.ModelState.IsValid)
     {
         var result = new CoreResult();
         foreach (var item in filterContext.ModelState.Values)
         {
             foreach (var error in item.Errors)
             {
                 result.Message += error.ErrorMessage + "|";
             }
         }
         if (!string.IsNullOrWhiteSpace(result.Message))
         {
             result.Message = result.Message.Remove(result.Message.Length - 1, 1);
         }
         filterContext.Result = new JsonResult(result);
     }
 }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public CoreResult Delete(int[] ids, int?userId = default(int?), bool checkPermission = false)
        {
            #region Kiểm tra quyền
            var per = this.CheckPermission(userId, checkPermission, ActionType.Delete);
            if (!per.Item1)
            {
                return(per.Item2);
            }
            #endregion
            CoreResult resultReturn = new CoreResult();
            using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
            {
                foreach (int id in ids)
                {
                    var dichvu = this.GetByID(id);
                    if (dichvu != null)
                    {
                        dichvu.deleted = true;

                        dichvu.dateUpdated   = DateTime.Now;
                        dichvu.NumberUpdated = Convert.ToByte(dichvu.NumberUpdated + 1);
                        this.context.Entry <DMDichVu>(dichvu).State = EntityState.Modified;
                    }
                }
                try
                {
                    this.context.SaveChanges();
                    dbTransaction.Commit();
                    resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                }
            }
            if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
            {
                this.RefreshCache();
            }
            return(resultReturn);
        }
        public void OnException(ExceptionContext context)
        {
            var json = new CoreResult();

            if (context.Exception.GetType() == typeof(CoreException))
            {
                json.Failed(context.Exception.Message);
                context.Result = new BadRequestObjectResult(json);
            }
            else
            {
                json.Failed("发生了未知错误");
                if (_env.IsDevelopment())
                {
                    json.Failed(context.Exception.StackTrace);
                }
                context.Result = new InternalServerErrorObjectResult(json);
            }
            _logger.LogError(context.Exception, context.Exception.Message);
            context.ExceptionHandled = true;
        }
Exemple #19
0
 public CoreResult Delete(int key, int?userId = default(int?), bool checkPermission = false)
 {
     try
     {
         this.CreateConnection();
         this.sqlHelper.CommandType = System.Data.CommandType.StoredProcedure;
         SqlDataReader dr          = this.sqlHelper.ExecuteReader("[KhamBenh_Delete]", new string[] { "@KhamBenhID", "@userID" }, new object[] { key, userId });
         CoreResult    returnValue = this.GetCustomMessage(dr, ActionType.Delete);
         if (returnValue != null)
         {
             return(returnValue);
         }
         else
         {
             return(this.GetResultFromSqlDataReader(dr, ActionType.Delete));
         }
     }
     catch (Exception e)
     {
         this.sqlHelper.Close();
         //log.Error("GetAll", e);
         return(this.GetResultFromStatusCode(CoreStatusCode.Exception, ActionType.Delete, e));
     }
 }
Exemple #20
0
        public CoreResult Query(List <IntPoint> points, double markerSize)
        {
            Console.WriteLine("Query");
            lock (this)
            {
                var result = new CoreResult();

                // 마커 정보
                var half = (float)(markerSize / 2);

                var objectMatrix = new[]
                {
                    half, half, 0,
                    half, -half, 0,
                    -half, -half, 0,
                    -half, half, 0
                };

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        _object.Set2D(i, j, objectMatrix[i * 3 + j]);
                    }
                }

                // 이미지 정보
                for (int i = 0; i < 4; i++)
                {
                    _image.Set2D(i, 0, points[i].X);
                    _image.Set2D(i, 1, points[i].Y);
                }

                try
                {
                    Console.WriteLine("Find");
                    CvInvoke.cvFindExtrinsicCameraParams2(
                        _object.CvPtr, _image.CvPtr, _camera.CvPtr, _distortion.CvPtr,
                        _rotation.CvPtr, _translation.CvPtr, false);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                // 결과
                result.RotationVector    = new List <float>(3);
                result.TranslationVector = new List <float>(3);

                for (int i = 0; i < 3; i++)
                {
                    result.RotationVector.Add((float)_rotation.Get2D(i, 0).Val0);
                    result.TranslationVector.Add((float)_translation.Get2D(i, 0).Val0);
                }

                result.Distance = Math.Sqrt(
                    result.TranslationVector[0] * result.TranslationVector[0] +
                    result.TranslationVector[1] * result.TranslationVector[1] +
                    result.TranslationVector[2] * result.TranslationVector[2]);

                Console.WriteLine("Diatance : {0}", result.Distance);

                return(result);
            }
        }
Exemple #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ids"></param>
 /// <param name="userID"></param>
 /// <param name="checkPermission"></param>
 /// <returns></returns>
 public CoreResult Delete(int[] ids, int?userID = null, bool checkPermission = false)
 {
     try
     {
         bool flag = false;
         if (userID == null && checkPermission)
         {
             return(new CoreResult {
                 StatusCode = CoreStatusCode.Failed, Message = "\"UserID\" không được phép để trống."
             });
         }
         else
         {
             if (checkPermission)
             {
                 var per = this.GetPermission(userID.Value, ActionType.Delete);
                 if (per.StatusCode == CoreStatusCode.OK)
                 {
                     ////action
                     flag = true;
                 }
                 else
                 {
                     return(per);
                 }
             }
             else
             {
                 ////action
                 flag = true;
             }
         }
         if (flag)
         {
             CoreResult resultReturn = new CoreResult();
             using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
             {
                 int _loai = (int)this._loaidanhmuc;
                 foreach (int id in ids)
                 {
                     var dantoc = this.Find(p => p.DanhMucID == id && p.LoaiDanhMuc == _loai);
                     if (dantoc != null)
                     {
                         this.context.Entry <DMDanhmuc>(dantoc).State = EntityState.Deleted;
                     }
                 }
                 try
                 {
                     this.context.SaveChanges();
                     dbTransaction.Commit();
                     resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                 }
                 catch (Exception ex)
                 {
                     dbTransaction.Rollback();
                     resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                 }
             }
             if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
             {
                 this.RefreshCache();
             }
             return(resultReturn);
         }
         else
         {
             return(new CoreResult {
                 StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.DontHavePermission, ActionType.Delete)
             });
         }
     }
     catch (Exception ex)
     {
         return(new CoreResult {
             StatusCode = CoreStatusCode.Exception, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex)
         });
     }
 }
Exemple #22
0
        /// <summary>
        /// Xóa nhóm bộ phận theo danh sách Mã bộ phận
        /// </summary>
        /// <param name="ids">Mảng int[]: danh sách mã bộ phận cần xóa</param>
        /// <param name="userID"></param>
        /// <param name="checkPermission"></param>
        /// <returns></returns>
        public CoreResult Delete(int[] ids, int?userID = null, bool checkPermission = false)
        {
            bool flag = false;

            if (userID == null && checkPermission)
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.Failed, Message = "\"UserID\" không được phép để trống."
                });
            }
            else
            {
                if (checkPermission)
                {
                    var per = this.GetPermission(userID.Value, ActionType.Delete);
                    if (per.StatusCode == CoreStatusCode.OK)
                    {
                        ////action
                        flag = true;
                    }
                    else
                    {
                        return(per);
                    }
                }
                else
                {
                    ////action
                    flag = true;
                }
            }
            if (flag)
            {
                CoreResult resultReturn = new CoreResult();
                using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
                {
                    foreach (int id in ids)
                    {
                        var department = this.GetByID(id);
                        if (department != null && !this.Any(p => p.DepartmentsID_TrucThuoc == id))
                        {
                            department.deleted = true;

                            this.context.Entry <Department>(department).State = EntityState.Modified;
                        }
                    }

                    try
                    {
                        this.context.SaveChanges();
                        dbTransaction.Commit();
                        resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                    }
                }
                if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
                {
                    this.RefreshCache();
                }
                return(resultReturn);
            }
            else
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.DontHavePermission, ActionType.Delete)
                });
            }
        }
 internal virtual CoreResult DeleteMultipleBase(KeyType[] primaryKeys, int userID)
 {
     try
     {
         CheckDbContext(mossHospitalEntities);
         CoreResult resultReturn = new CoreResult();
         using (DbContextTransaction dbTransaction = mossHospitalEntities.Database.BeginTransaction())
         {
             if (DeleteTemp)
             {
                 GetValuesUpdateWhenDelete();
                 valuesDeletes.Add("userIDUpdated", userID);
                 foreach (KeyType id in primaryKeys)
                 {
                     var model = GetT(id);
                     if (model != null)
                     {
                         SetValuesDelete(model);
                         mossHospitalEntities.Set <T>().Attach(model);
                         mossHospitalEntities.Entry <T>(model).State = EntityState.Modified;
                     }
                 }
             }
             else
             {
                 foreach (KeyType id in primaryKeys)
                 {
                     var model = GetT(id);
                     if (model != null)
                     {
                         mossHospitalEntities.Entry <T>(model).State = EntityState.Deleted;
                     }
                 }
             }
             try
             {
                 mossHospitalEntities.SaveChanges();
                 dbTransaction.Commit();
                 resultReturn.StatusCode = CoreStatusCode.OK;
                 resultReturn.Message    = GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
             }
             catch (Exception ex)
             {
                 dbTransaction.Rollback();
                 resultReturn.StatusCode     = CoreStatusCode.Exception;
                 resultReturn.Message        = GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                 resultReturn.ExceptionError = GetMessageException(ex);
             }
         }
         if (resultReturn.StatusCode == CoreStatusCode.OK && _useCache)
         {
             RefreshCache();
         }
         return(resultReturn);
     }
     catch (Exception ex)
     {
         return(new CoreResult {
             StatusCode = CoreStatusCode.Exception, Data = primaryKeys, Message = GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex), ExceptionError = GetMessageException(ex)
         });
     }
 }
        public CoreResult Delete(int[] ids, int? userID = null, bool checkPermission = false)
        {
            try
            {
                bool flag = false;
                if (userID == null && checkPermission)
                {
                    return new CoreResult { StatusCode = CoreStatusCode.Failed, Message = "\"UserID\" không được phép để trống." };
                }
                else
                {
                    if (checkPermission)
                    {
                        var per = this.GetPermission(userID.Value, ActionType.Delete);
                        if (per.StatusCode == CoreStatusCode.OK)
                        {
                            ////action
                            flag = true;
                        }
                        else return per;
                    }
                    else
                    {
                        ////action
                        flag = true;
                    }
                }
                if (flag)
                {
                    CoreResult resultReturn = new CoreResult();
                    using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
                    {
                        foreach (int id in ids)
                        {
                            var tinhthanh = this.GetByID(id);
                            if (tinhthanh != null)
                            {
                                this.context.Entry<DMTinhThanh>(tinhthanh).State = EntityState.Deleted;
                            }
                        }
                        try
                        {
                            this.context.SaveChanges();
                            dbTransaction.Commit();
                            resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                        }
                        catch (Exception ex)
                        {
                            dbTransaction.Rollback();
                            resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                        }

                    }
                    if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
                    {
                        this.RefreshCache();
                    }
                    return resultReturn;
                }
                else
                {
                    return new CoreResult { StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.DontHavePermission, ActionType.Delete) };
                }

            }
            catch (Exception ex)
            {
                return new CoreResult { StatusCode = CoreStatusCode.Exception, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex) };
            }

        }
Exemple #25
0
 public CoreResult Update(RaVien entity, int?userId = default(int?), bool checkPermission = false)
 {
     try
     {
         #region Kiểm tra quyền thao tác
         var result = this.CheckPermission(userId, checkPermission, ActionType.Edit);
         #endregion
         if (result.Item1)
         {
             //kiểm tra Id bộ phận có phải là ID bộ phận trong khám bệnh cuối cùng không
             if (entity.DepartmentID_TK == new KhamBenh().GetIDBoPhan_TrongKhamBenhCuoiCung(entity.patientsID))
             {
                 //kiểm tra ngày ra viện
                 var _kiemtrangayravien = this.KiemtraNgayRavien(entity.patientsID, entity.NgayRaVien);
                 if (_kiemtrangayravien.Item1)
                 {
                     //kiểm tra thanh toán(đã thanh toán, không cho cập nhật ra viện)
                     var _kiemtrathanhtoan = new ThanhToanProvider().KiemTraThanhToan(entity.patientsID);
                     if (!_kiemtrathanhtoan)
                     {
                         #region Cập nhật ra viện
                         this.CreateConnection();
                         this.sqlHelper.CommandType = CommandType.StoredProcedure;
                         List <string> paramsName = new List <string> {
                             "@patientsID", "@NgayRaVien", "@SoNgayDT", "@KetQuaDT", "@HinhThucRV", "@SoRaVien",
                             "@SoLuuTru", "@MaYTe", "@DepartmentID_TK", "@PhuongPhapDT", "@TinhTrangRaVien",
                             "@DienBienLamSang", "@KetQuaCanLamSang", "@ChuyenKhoa_Code", "@LoiDan",
                             "@GhiChu", "@userIDUpdated"
                         };
                         List <object> paramsValue = new List <object> {
                             entity.patientsID, entity.NgayRaVien, entity.SoNgayDT, entity.KetQuaDT,
                             entity.HinhThucRV, entity.SoRaVien, entity.SoLuuTru, entity.MaYTe, entity.DepartmentID_TK,
                             entity.PhuongPhapDT, entity.TinhTrangRaVien, entity.DienBienLamSang, entity.KetQuaCanLamSang,
                             entity.ChuyenKhoa_Code, entity.LoiDan, entity.GhiChu, entity.userIDUpdated
                         };
                         if (entity.HinhThucRV == (byte)Library.Constants.HinhThucRaVien.ChuyenVien)
                         {
                             //chuyen vien
                             paramsName.AddRange(new List <string> {
                                 "@MaBenhVien_CV", "@TinhTrangCV", "@LyDoCV", "@HinhThucCV", "@HanCV", "@ChanDoanCV", "@NguoiChuyen", "@KetQua"
                             });
                             paramsValue.AddRange(new List <object> {
                                 entity.ThongtinChuyenvien.patientsID,
                                 entity.ThongtinChuyenvien.MaBenhVien_CV, entity.ThongtinChuyenvien.TinhTrangCV,
                                 entity.ThongtinChuyenvien.LyDoCV, entity.ThongtinChuyenvien.HinhThucCV, entity.ThongtinChuyenvien.HanCV,
                                 entity.ThongtinChuyenvien.ChanDoanCV, entity.ThongtinChuyenvien.NguoiChuyen, entity.ThongtinChuyenvien.KetQua
                             });
                         }
                         SqlDataReader dr          = this.sqlHelper.ExecuteReader("[RaVien_Update]", paramsName.ToArray(), paramsValue.ToArray());
                         CoreResult    returnValue = this.GetCustomMessage(dr, ActionType.Edit);
                         if (returnValue != null)
                         {
                             return(returnValue);
                         }
                         else
                         {
                             return(this.GetResultFromSqlDataReader(dr, ActionType.Edit));
                         }
                         #endregion
                     }
                     else
                     {
                         //bệnh nhân đã thanh toán
                         return(new CoreResult
                         {
                             StatusCode = CoreStatusCode.Failed,
                             Message = "Bệnh nhân đã thanh toán, không được sửa ra viện."
                         });
                     }
                 }
                 else
                 {
                     return(new CoreResult
                     {
                         StatusCode = CoreStatusCode.Failed,
                         Message = _kiemtrangayravien.Item2
                     });
                 }
             }
             else
             {
                 //không phải ID bộ phận cuối cùng
                 var    bophan    = new Department().GetByID(entity.DepartmentID_TK);
                 string tenbophan = bophan == null ? string.Empty : bophan.DepartmentsName;
                 return(new CoreResult
                 {
                     StatusCode = CoreStatusCode.Failed,
                     Message = string.Format("\"{0}\" không phải là bộ phận khám bệnh cuối cùng, không được cho thêm ra viện cho bệnh nhân này.", tenbophan)
                 });
             }
         }
         else
         {
             return(result.Item2);
         }
     }
     catch (Exception e)
     {
         this.sqlHelper.Close();
         return(this.GetResultFromStatusCode(CoreStatusCode.Exception, ActionType.Edit, e));
     }
 }
        /// <summary>
        /// Xóa nhóm, tiểu nhóm dịch vụ theo danh sách Mã nhóm, tiểu nhóm dịch vụ
        /// </summary>
        /// <param name="ids">Mảng int[]: danh sách mã nhóm, tiểu nhóm dịch vụ cần xóa</param>
        /// <returns></returns>
        public CoreResult Delete(int[] ids, int?userID = null, bool checkPermission = false)
        {
            bool flag = false;

            if (userID == null && checkPermission)
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.Failed, Message = "\"UserID\" không được phép để trống."
                });
            }
            else
            {
                if (checkPermission)
                {
                    var per = this.GetPermission(userID.Value, ActionType.Delete);
                    if (per.StatusCode == CoreStatusCode.OK)
                    {
                        ////action
                        flag = true;
                    }
                    else
                    {
                        return(per);
                    }
                }
                else
                {
                    ////action
                    flag = true;
                }
            }
            if (flag)
            {
                CoreResult resultReturn = new CoreResult();
                using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
                {
                    foreach (int id in ids)
                    {
                        var dmnhomdichvu = this.GetByID(id);
                        if (dmnhomdichvu != null)
                        {
                            dmnhomdichvu.dateUpdated   = DateTime.Now;
                            dmnhomdichvu.NumberUpdated = Convert.ToByte(dmnhomdichvu.NumberUpdated + 1);
                            dmnhomdichvu.deleted       = true;
                            this.context.Entry <DMNhomDichVu>(dmnhomdichvu).State = EntityState.Modified;
                        }
                    }

                    try
                    {
                        this.context.SaveChanges();
                        dbTransaction.Commit();
                        resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                    }
                    catch (Exception ex)
                    {
                        dbTransaction.Rollback();
                        resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                    }
                }
                if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
                {
                    this.RefreshCache();
                }
                return(resultReturn);
            }
            else
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.DontHavePermission, ActionType.Delete)
                });
            }
        }
Exemple #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mabenhvien"></param>
        /// <param name="userID"></param>
        /// <param name="checkPermission"></param>
        /// <returns></returns>
        public CoreResult Delete(string[] mabenhvien, int?userID = null, bool checkPermission = false)
        {
            try
            {
                bool flag = false;
                if (userID == null && checkPermission)
                {
                    return(new CoreResult {
                        StatusCode = CoreStatusCode.Failed, Message = "\"UserID\" không được phép để trống."
                    });
                }
                else
                {
                    if (checkPermission)
                    {
                        var per = this.GetPermission(userID.Value, ActionType.Delete);
                        if (per.StatusCode == CoreStatusCode.OK)
                        {
                            ////action
                            flag = true;
                        }
                        else
                        {
                            return(per);
                        }
                    }
                    else
                    {
                        ////action
                        flag = true;
                    }
                }
                if (flag)
                {
                    CoreResult resultReturn = new CoreResult();
                    using (DbContextTransaction dbTransaction = this.context.Database.BeginTransaction())
                    {
                        foreach (string id in mabenhvien)
                        {
                            var benhvien = this.GetByID(id);
                            if (benhvien != null)
                            {
                                benhvien.deleted = true;

                                this.context.Entry <DMBenhVien>(benhvien).State = EntityState.Modified;
                            }
                        }
                        try
                        {
                            this.context.SaveChanges();
                            dbTransaction.Commit();
                            resultReturn.StatusCode = CoreStatusCode.OK; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.OK, ActionType.Delete);
                        }
                        catch (Exception ex)
                        {
                            dbTransaction.Rollback();
                            resultReturn.StatusCode = CoreStatusCode.Exception; resultReturn.Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex);
                        }
                    }
                    if (resultReturn.StatusCode == CoreStatusCode.OK && this.GetUseCache())
                    {
                        this.RefreshCache();
                    }
                    return(resultReturn);
                }
                else
                {
                    return(new CoreResult {
                        StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.DontHavePermission, ActionType.Delete)
                    });
                }
            }
            catch (Exception ex)
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.Exception, Message = this.GetMessageByCoreStatusCode(CoreStatusCode.Exception, ActionType.Delete, ex)
                });
            }
        }