Beispiel #1
0
        public async Task <IEnumerable <DepartmentModel> > GetAllDepartments(int divisionId)
        {
            // In-Memory Cache Example
            const string cacheKey = "departments";

            var cachedResponse = _memoryCache.Get <IEnumerable <DepartmentModel> >(cacheKey);

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

            var departments = (await _misService.GetAllDepartments(divisionId)).ToList();

            _memoryCache.Set(cacheKey, departments, TimeSpan.FromSeconds(86400));

            return(departments.OrderBy(x => x.DepartmentName));
        }
Beispiel #2
0
        public async Task <ActionResult <IEnumerable <DepartmentModel> > > GetAll()
        {
            _logger.LogInformationExtension("Get All Departments");
            var departments = await _misService.GetAllDepartments();

            string message;

            if (departments == null)
            {
                message = "No departments found";
                _logger.LogErrorExtension(message, null);
                return(NotFound(new Models.Response <DepartmentModel>(false, message)));
            }

            message = $"Found {departments.Count()} departments";

            _logger.LogInformationExtension(message);

            return(Ok(new Models.Response <IEnumerable <DepartmentModel> >(departments, message)));
        }