public async Task <IActionResult> GetAllTasks()
        {
            try
            {
                _logger.LogInfo($"Returned all projects from database.");
                if (!_memoryCache.TryGetValue("Entities", out IEnumerable <TaskEntity> entities))
                {
                    var cacheExpirationOptions = new MemoryCacheEntryOptions
                    {
                        AbsoluteExpiration = DateTime.Now.AddHours(6),
                        Priority           = CacheItemPriority.Normal,
                        SlidingExpiration  = TimeSpan.FromMinutes(5)
                    };
                    _memoryCache.Set("Entities", await _taskRepository.ReadAllASync(), cacheExpirationOptions);
                }
                entities = _memoryCache.Get("Entities") as IEnumerable <TaskEntity>;

                TaskDto        presentation = null;
                List <TaskDto> taskDtos     = new();

                foreach (var entity in entities)
                {
                    presentation = _mapper.Map <TaskDto>(entity);
                    taskDtos.Add(presentation);
                }

                return(Ok(taskDtos));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside ReadAll action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <IActionResult> GetAllProjects()
        {
            try
            {
                _logger.LogInfo($"Returned all projects from database.");
                if (!_memoryCache.TryGetValue("Entities", out IEnumerable <ProjectEntity> entities))
                {
                    _memoryCache.Set("Entities", await _projectRepository.ReadAllASync());
                }
                entities = _memoryCache.Get("Entities") as IEnumerable <ProjectEntity>;

                ProjectDto        presentation = null;
                List <ProjectDto> projectDtos  = new();

                foreach (var entity in entities)
                {
                    presentation = _mapper.Map <ProjectDto>(entity);
                    projectDtos.Add(presentation);
                }

                return(Ok(projectDtos));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside ReadAll action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#3
0
        public IActionResult GetAllOwners()
        {
            try
            {
                var owner = _repository.Owner.GetAllOwners();
                // var owner = new string[] { "value1", "value2" };

                _logger.LogInfo($"Returned all owners from databse.");

                return(Ok(owner));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside GetAllOwners action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#4
0
 public IActionResult Notifications(string email)
 {
     RecurringJob.AddOrUpdate(() => _notification.SendEmailNotification(email), Cron.Monthly);
     _logger.LogInfo("Sending emails scheduled!");
     return(Ok($"Recurring Job Scheduled. Invoice will be mailed Monthly for {email}!"));
 }