public async Task <IActionResult> Index()
        {
            try
            {
                string cpFileKey           = nameof(CPFileSummaryViewModel);
                string hospitalPracticeKey = nameof(HospitalPracticeSummaryViewModel);

                if (!MedicCache.TryGetValue(cpFileKey, out List <CPFileSummaryViewModel> cpFiles))
                {
                    cpFiles = await CPFileService.GetSummaryByMonthAsync();

                    MedicCache.Set(cpFileKey, cpFiles);
                }

                if (!MedicCache.TryGetValue(hospitalPracticeKey, out List <HospitalPracticeSummaryViewModel> hospitalPractices))
                {
                    hospitalPractices = await HospitalPracticeService.GetSummaryByMonthAsync();

                    MedicCache.Set(hospitalPracticeKey, hospitalPractices);
                }

                if (!MedicCache.TryGetValue(MedicConstants.PatientsCount, out int patientsCount))
                {
                    patientsCount = await PatientService.GetPatientsCountAsync(new PatientWhereBuilder(default));
Exemple #2
0
        public IEnumerable <Order> GetOrders()
        {
            Console.WriteLine("Get Orders");

            var user   = Thread.CurrentPrincipal.Identity.Name;
            var orders = cache.Get(user);

            if (orders == null)
            {
                Console.WriteLine("From DB");

                using (var dbContext = new Northwind())
                {
                    dbContext.Configuration.LazyLoadingEnabled   = false;
                    dbContext.Configuration.ProxyCreationEnabled = false;
                    orders = dbContext.Orders.ToList();
                    cache.Set(user, orders, policy);
                }
            }

            return(orders);
        }
Exemple #3
0
        /// <summary>
        /// Get all mapped properties of type T.  (Properties with the DbField attribute)
        /// Returns a list of tuples with the following:
        ///   ( Database Field Name, Reflected Property, If the property is a nullable type )
        /// </summary>
        /// <typeparam name="T">Data Type</typeparam>
        /// <returns>List of DbMappings</returns>
        private static List <DbMapping> GetDatabaseProperties <T>()
        {
            var type = typeof(T);

            var cachedObject = cache.Get(type.FullName);

            if (cachedObject != null)
            {
                return(cachedObject);
            }

            var properties = type.GetProperties();
            var result     = new List <DbMapping>();

            foreach (var property in properties)
            {
                var attrib = property.GetCustomAttribute <DbFieldAttribute>(true);

                if (attrib != null)
                {
                    var isNullable = Nullable.GetUnderlyingType(property.PropertyType) != null || !property.PropertyType.IsValueType;

                    var mapping = new DbMapping()
                    {
                        DatabaseField  = attrib.Field ?? property.Name,
                        ObjectProperty = property,
                        IsNullable     = isNullable
                    };
                    result.Add(mapping);
                }
            }

            cache.Set(type.FullName, result);

            return(result);
        }