Ejemplo n.º 1
0
        public async Task <IActionResult> Index(int collectionId)
        {
            var collection = await _collectionsService.GetCollectionById(collectionId);

            var returnPeriods = await _collectionsService.GetReturnPeriodsForCollection(collectionId);

            var now = _dateTimeProvider.GetNowUtc();

            var currentPeriod = returnPeriods.SingleOrDefault(rp => rp.OpenDate <= now && rp.CloseDate >= now);

            if (currentPeriod == null && now <= returnPeriods.Max(rp => rp.CloseDate))
            {
                // in between open periods - set current period to next available one.
                currentPeriod = returnPeriods.OrderBy(o => o.OpenDate).FirstOrDefault(w => w.OpenDate > now);
            }

            var model = new ManageCollectionViewModel()
            {
                CollectionId       = collection.CollectionId,
                CollectionName     = collection.CollectionTitle,
                ClosingDate        = currentPeriod?.CloseDate,
                CurrentPeriod      = currentPeriod?.Name,
                ProcessingOverride = SetOverrideValue(collection.ProcessingOverride),
                ReturnPeriods      = returnPeriods.ToList()
            };

            if (currentPeriod != null)
            {
                model.DaysRemaining = (currentPeriod.CloseDate - now).Days;
            }

            return(View("IndividualCollection", model));
        }