/// <summary>
 ///
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="fetureName"></param>
 /// <param name="_actionType"></param>
 /// <returns></returns>
 public CoreResult GetPermission(string userName, string fetureName, ActionType _actionType)
 {
     try
     {
         using (MossHospitalEntities context = new MossHospitalEntities())
         {
             var user = context.Users.FirstOrDefault(p => p.userName == userName);
             if (user != null)
             {
                 return(this.GetPermission(user.userID, fetureName, _actionType));
             }
             else
             {
                 return(new CoreResult {
                     StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessagePermission(fetureName, _actionType)
                 });
             }
         }
     }
     catch (Exception)
     {
         return(new CoreResult {
             StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessagePermission(fetureName, _actionType)
         });
     }
 }
Exemplo n.º 2
0
 private void CheckDbContext(MossHospitalEntities mossHospital)
 {
     if (mossHospital == null || !CheckAutoDetectChanges(mossHospital))
     {
         throw new ArgumentNullException(string.Format("\"MossHospitalEntities\": NULL hoặc \"AutoDetectChanges\" = \"false\"."));
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="fetureCode"></param>
        /// <param name="_actionType"></param>
        /// <returns></returns>
        public CoreResult GetPermission(int userId, string fetureCode, ActionType _actionType)
        {
            try
            {
                using (MossHospitalEntities context = new MossHospitalEntities())
                {
                    var query = (from feture in context.Features
                                 join per in context.Permissions on feture.FeatureID equals per.FeatureID
                                 where feture.FeatureCode == fetureCode && per.userID == userId
                                 select new { per, fetureCode = feture.FeatureCode, featureName = feture.FeatureName }).FirstOrDefault();
                    if (query == null)
                    {
                        return(new CoreResult {
                            StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessagePermission(fetureCode, _actionType)
                        });
                    }
                    else
                    {
                        switch (_actionType)
                        {
                        case ActionType.View:
                            return(new CoreResult {
                                StatusCode = query.per.Views ? CoreStatusCode.OK : CoreStatusCode.DontHavePermission, Message = query.per.Views ? string.Empty : this.GetMessagePermission(query.featureName, _actionType)
                            });

                        case ActionType.Insert:
                            return(new CoreResult {
                                StatusCode = query.per.New ? CoreStatusCode.OK : CoreStatusCode.DontHavePermission, Message = query.per.New ? string.Empty : this.GetMessagePermission(query.featureName, _actionType)
                            });

                        case ActionType.Edit:
                            return(new CoreResult {
                                StatusCode = query.per.Edit ? CoreStatusCode.OK : CoreStatusCode.DontHavePermission, Message = query.per.Edit ? string.Empty : this.GetMessagePermission(query.featureName, _actionType)
                            });

                        case ActionType.Delete:
                            return(new CoreResult {
                                StatusCode = query.per.Deleted ? CoreStatusCode.OK : CoreStatusCode.DontHavePermission, Message = query.per.Deleted ? string.Empty : this.GetMessagePermission(query.featureName, _actionType)
                            });

                        case ActionType.Print:
                            return(new CoreResult {
                                StatusCode = query.per.Prints ? CoreStatusCode.OK : CoreStatusCode.DontHavePermission, Message = query.per.Prints ? string.Empty : this.GetMessagePermission(query.featureName, _actionType)
                            });

                        default:
                            return(new CoreResult {
                                StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessagePermission(query.featureName, _actionType)
                            });
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(new CoreResult {
                    StatusCode = CoreStatusCode.DontHavePermission, Message = this.GetMessagePermission(fetureCode, _actionType)
                });;
            }
        }
Exemplo n.º 4
0
 internal void GetDbContext()
 {
     if (mossHospitalEntities == null)
     {
         mossHospitalEntities = new MossHospitalEntities();
     }
     mossHospitalEntities.Configuration.AutoDetectChangesEnabled = false;
     mossHospitalEntities.Configuration.ProxyCreationEnabled     = false;
     //return mossHospitalEntities;
 }
Exemplo n.º 5
0
 public void LoadCache(CacheType _cacheType)
 {
     if (IsLoadCache)
     {
         if (_cacheType == CacheType.All)
         {
             if (!loaded)
             {
                 MossHospitalEntities dbContext = new MossHospitalEntities();
                 List <CacheType>     caches    = new List <CacheType>();
                 caches.Add(CacheType.Department);
                 caches.Add(CacheType.DMBenhVien);
                 caches.Add(CacheType.DMDichVu);
                 caches.Add(CacheType.DMDichVuCL);
                 caches.Add(CacheType.DMDuoc);
                 caches.Add(CacheType.DMICD10);
                 caches.Add(CacheType.DMNhomDichVu);
                 caches.Add(CacheType.Employee);
                 caches.Add(CacheType.Permission);
                 caches.Add(CacheType.DMTinhThanh);
                 caches.Add(CacheType.DMQuanHuyen);
                 caches.Add(CacheType.DMXaPhuong);
                 caches.Add(CacheType.DMDanhMuc);
                 caches.Add(CacheType.PatientsObject);
                 caches.Add(CacheType.Feature);
                 caches.Add(CacheType.AssetsType);
                 caches.Add(CacheType.AssetsCate);
                 caches.Add(CacheType.Asset);
                 caches.Add(CacheType.DMMucHuong);
                 //this.LoadCache(CacheType.All, dbContext);
                 foreach (CacheType item in caches)
                 {
                     var task = Task.Run(() => {
                         LoadCache(item);
                     });
                     task.Wait();
                 }
             }
         }
         else
         {
             MossHospitalEntities dbContext = new MossHospitalEntities();
             this.LoadCache(_cacheType, dbContext);
         }
         loaded = true;
     }
 }
 internal Tuple <CoreStatusCode, T> SaveChange(KeyType id, T item)
 {
     try
     {
         using (var db = new  MossHospitalEntities())
         {
             var model = db.Set <T>().Find(id);
             if (model != null)
             {
                 //db.Entry<T>(model).State = EntityState.Detached;
                 db.Entry <T>(item).State = EntityState.Modified;
                 int counter = db.SaveChanges();
                 db.Entry <T>(item).GetDatabaseValues();
                 if (_useCache)
                 {
                     if (counter > 0)
                     {
                         this.RefreshCache();
                         return(Tuple.Create(CoreStatusCode.OK, item));
                     }
                     else
                     {
                         return(Tuple.Create(CoreStatusCode.Failed, item));
                     }
                 }
                 return(Tuple.Create(counter >= 0 ? CoreStatusCode.OK : CoreStatusCode.Failed, item));
             }
             else
             {
                 return(Tuple.Create(CoreStatusCode.NotFound, item));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 /// <summary>
 /// Khởi tạo với DbContext
 /// </summary>
 /// <param name="db">DbContext Entities</param>
 public EntityFrameworkRepository(MossHospitalEntities db)
 {
     this.context = db;
     this.dbSet   = this.context.Set <T>();
     this.context.Configuration.ProxyCreationEnabled = false;
 }
Exemplo n.º 8
0
 public void Dispose()
 {
     mossHospitalEntities = null;
     GC.SuppressFinalize(this);
 }
Exemplo n.º 9
0
 private bool CheckAutoDetectChanges(MossHospitalEntities mossHospital)
 {
     return(mossHospital == null ? false : mossHospital.Configuration.AutoDetectChangesEnabled);
 }
Exemplo n.º 10
0
        private void LoadCache(CacheType _cacheType, MossHospitalEntities _dbContext)
        {
            switch (_cacheType)
            {
            case CacheType.Permission:
                GlobalCache.Permissions = _dbContext.Permissions.ToList();
                break;

            case CacheType.Department:
                GlobalCache.departments = _dbContext.Departments.ToList();
                break;

            case CacheType.Employee:
                GlobalCache.Employees = _dbContext.Employees.ToList();
                break;

            case CacheType.DMDichVuCL:
                GlobalCache.dMDichVuCLs = _dbContext.DMDichVuCLSangs.ToList();
                break;

            case CacheType.DMDichVu:
                GlobalCache.dMDichVus = _dbContext.DMDichVus.ToList();
                break;

            case CacheType.DMDuoc:
                GlobalCache.DMDuocs = _dbContext.DMDuocs.ToList();
                break;

            case CacheType.DMNhomDichVu:
                GlobalCache.dMNhomDichVus = _dbContext.DMNhomDichVus.ToList();
                break;

            case CacheType.DMICD10:
                GlobalCache.dMICD10s = _dbContext.DMICD10.ToList();
                break;

            case CacheType.DMBenhVien:
                GlobalCache.dMBenhViens = _dbContext.DMBenhViens.ToList();
                break;

            case CacheType.All:
                break;

            case CacheType.DMTinhThanh:
                GlobalCache.DMTinhThanhs = _dbContext.DMTinhThanhs.ToList();
                break;

            case CacheType.DMQuanHuyen:
                GlobalCache.DMQuanHuyens = _dbContext.DMQuanHuyens.ToList();
                break;

            case CacheType.DMXaPhuong:
                GlobalCache.DMXaPhuongs = _dbContext.DMXaPhuongs.ToList();
                break;

            case CacheType.DMDanhMuc:
                GlobalCache.DMDanhmucs = _dbContext.DMDanhmucs.ToList();
                break;

            case CacheType.PatientsObject:
                GlobalCache.PatientsObjects = _dbContext.patientsObjects.ToList();
                break;

            case CacheType.Feature:
                GlobalCache.Features = _dbContext.Features.ToList();
                break;

            case CacheType.SystemConfig:
                GlobalCache.SystemConfigs = _dbContext.SystemConfigs.ToList();
                break;

            case CacheType.AssetsType:
                GlobalCache.AssetsTypes = _dbContext.AssetsTypes.ToList();
                break;

            case CacheType.AssetsCate:
                GlobalCache.AssetsCates = _dbContext.AssetsCates.ToList();
                break;

            case CacheType.Asset:
                GlobalCache.Assets = _dbContext.Assets.ToList();
                break;

            case CacheType.DMMucHuong:
                GlobalCache.DMMucHuongs = _dbContext.DMMucHuongs.ToList();
                break;

            default:
                break;
            }
        }