Beispiel #1
0
        public IHttpActionResult Get(int?filterId = null, string sortBy = null, string sortOrder = null)
        {
            #region Preconditions

            if (userTaskRepository == null)
            {
                throw new InvalidOperationException();
            }

            #endregion

            try
            {
                logger.Info($"TasksController Get: {filterId}, sortBy: {sortBy}, sortOrder: {sortOrder}", users.First(u => u.UserName == User.Identity.Name).Id);

                IEnumerable <UserTask> userTasks = null;

                if (filterId != null)
                {
                    // This cast is appropriate, we need the specific UserTaskRepository behaviour here.
                    userTasks = ((UserTaskRepository)userTaskRepository).GetItems(filterId.Value);
                }
                else
                {
                    userTasks = userTaskRepository.GetItems();
                }

                var dtoTasks = userTasks.Select(ut => UserTaskMapper.TranslateModelUserTaskToDTOTask(ut));

                var taskInfoList = new DTO.TaskList
                {
                    Metadata = new DTO.TaskListMetadata
                    {
                        Count     = dtoTasks.Count(),
                        FilterId  = filterId,
                        SortBy    = sortBy,
                        SortOrder = sortOrder
                    },
                    Tasks = dtoTasks
                };

                logger.Info($"TasksController Get taskInfoList Count: {taskInfoList.Tasks.Count()}", users.First(u => u.UserName == User.Identity.Name).Id);

                return(Ok(taskInfoList));
            }
            catch (Exception ex)
            {
                logger.Error($"TasksController Get Error: {ex.Message}", users.First(u => u.UserName == User.Identity.Name).Id);
                return(InternalServerError());
            }
        }