private List <PreservationSchedule> GetArchivePeriods(Guid archiveId)
        {
            var retval = new List <PreservationSchedule>();

            try
            {
                var service = new PreservationService();
                var periods = service.GetSchedule();

                //PreservationSchedule previouslyUsedSchedule = null;

                var selSchedule = service.GetPreservationScheduleWithinArchive(archiveId);
                if (selSchedule != null)
                {
                    foreach (var item in periods)
                    {
                        item.IsArchiveDefault = item.IdPreservationSchedule == selSchedule.IdPreservationSchedule;
                    }
                }
                retval = new List <PreservationSchedule>(periods);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }

            return(retval);
        }
        private PreservationTaskViewModel ArchivePreservationModel(Guid id)
        {
            var service  = new PreservationService();
            var archive  = ArchiveService.GetArchive(id);
            var schedule = service.GetPreservationScheduleWithinArchive(id);
            var SelectedScheduleIndex = -1;
            var schedulePeriod        = GetArchivePeriods(id);
            var tasks = service.GetPreservationTasks(new System.ComponentModel.BindingList <DocumentArchive> {
                new DocumentArchive(id)
            }, 0, 2);
            DateTime             nextPreservationDate = DateTime.Now;
            PreservationSchedule objSched             = null;

            if (schedule != null)
            {
                objSched = schedulePeriod.Where(x => x.IdPreservationSchedule == schedule.IdPreservationSchedule).FirstOrDefault();
                if (objSched != null)
                {
                    SelectedScheduleIndex = schedulePeriod.IndexOf(objSched);
                }
            }

            if (tasks.Tasks.Count > 0)
            {
                nextPreservationDate = tasks.Tasks.First().EndDocumentDate.Value.AddDays(1);
            }
            var viewModel = new PreservationTaskViewModel {
                IdArchive = id, ArchiveName = archive.Name, SelectedScheduleIndex = SelectedScheduleIndex, PeriodSchedulers = schedulePeriod, NextPreservationTaskStartDocumentDate = nextPreservationDate
            };

            return(viewModel);
        }