Exemplo n.º 1
0
        public async Task <List <Task> > GetUnsynced(DateTime lastSyncDate)
        {
            try
            {
                var response = await _serviceStackClient.PostAsync(new TasksRequest { LastSyncDate = lastSyncDate });

                var returnList = new List <Task>();
                foreach (var task in response.Tasks)
                {
                    var project = _projectRepository.GetById(task.ProjectId);
                    if (project != null)
                    {
                        var timeRegistrationTypeEnum = (TimeRegistrationTypeEnum)(int)task.TimeRegistrationType; //now thats casting!
                        var item = Task.Create(task.Guid, task.Id, task.Name, task.Description, project, task.CreateDate, true, string.Empty,
                                               task.Inactive, timeRegistrationTypeEnum);
                        returnList.Add(item);
                    }
                    else
                    {
                        throw new MissingHieracleDataException(string.Format("Could not find projectId {0} for task '{1} ({2})'", task.ProjectId, task.Name, task.Id));
                    }
                }
                return(returnList);
            }
            catch (MissingHieracleDataException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ServiceAccessException("Error contacting service", ex);
            }
        }
Exemplo n.º 2
0
        private async Task <List <TimeEntry> > ConvertTimeEntriesFromServiceToModel(List <Common.DataTransferObjects.TimeEntryDto> timeentriesDtos,
                                                                                    ITaskRepository taskRepository, ITimeEntryTypeRepository timeEntryTypeRepository)
        {
            var timeEntries = new List <TimeEntry>();

            var inactiveTasksWithTimeEntriesInPeriod = await _serviceStackClient.PostAsync(new GetTasksByIdRequest
            {
                TaskIds = timeentriesDtos.Where(x => x.TaskIsInactive).Select(x => x.TaskId).ToList()
            });

            foreach (var timeEntryDtos in timeentriesDtos.GroupBy(x => x.TaskGuid))
            {
                Core.Model.Task localTask;

                var taskIsInactive = timeEntryDtos.Select(x => x.TaskIsInactive).First();
                if (taskIsInactive)
                {
                    var fullTaskDto = inactiveTasksWithTimeEntriesInPeriod.Tasks.Single(x => x.Guid == timeEntryDtos.Key);
                    localTask = CreateLocalTask(fullTaskDto);
                }
                else
                {
                    localTask = taskRepository.GetByGuid(timeEntryDtos.Key);
                }

                foreach (var timeEntryDto in timeEntryDtos)
                {
                    var timeEntryType = timeEntryTypeRepository.GetById(timeEntryDto.TimeEntryTypeId);
                    if (localTask != null)
                    {
                        timeEntries.Add(Create(timeEntryDto, localTask, timeEntryType));
                    }
                    else
                    {
                        throw new MissingHieracleDataException(string.Format("Could not find task {0} for timeEntry '{1} ({2})'",
                                                                             timeEntryDto.TaskGuid, timeEntryDto.TaskName, timeEntryDto.Id));
                    }
                }
            }
            return(timeEntries);
        }