protected internal override void SetupSecondaryData(DbContext db, IBizActionStatus status)
 {
     SetupSecondaryDataCalled = true;
     if (RaiseErrorInSetupSecondaryData)
     {
         status.AddError("Error in SetupSecondaryData");
     }
 }
예제 #2
0
 protected internal override async Task SetupSecondaryDataAsync(object repository, IBizActionStatus status)
 {
     SetupSecondaryDataCalled = true;
     if (RaiseErrorInSetupSecondaryData)
     {
         status.AddError("Error in SetupSecondaryData");
     }
 }
예제 #3
0
        /// <summary>
        /// This is called by the BizRunner’s GetOriginal or ResetDto methods.
        /// It sets up the presentation layer properties
        /// </summary>
        /// <param name="db">The DbContext to allow access to the database</param>
        /// <param name="status">The BizActionStatus so you can register errors</param>
        protected override void SetupSecondaryData(DbContext db, IBizActionStatus status)
        {
            if (OrderId == 0)
            {
                throw new InvalidOperationException("You must set the OrderId before you call SetupSecondaryData");
            }
            if (UserId == null)
            {
                throw new InvalidOperationException("You must set the UserId before you call SetupSecondaryData");
            }

            var order = db.Set <Order>()
                        .Include(x => x.LineItems).ThenInclude(x => x.ChosenBook)
                        .SingleOrDefault(x => x.OrderId == OrderId);

            if (order == null)
            {
                status.AddError("Sorry, I could not find the order you asked for.");
                HasErrors = true;
                //Log possible hacking
                return;
            }

            DateOrderedUtc       = order.DateOrderedUtc;
            OriginalDeliveryDate = order.ExpectedDeliveryDate;
            NewDeliveryDate      = OriginalDeliveryDate < DateTime.Today
                ? DateTime.Today
                : OriginalDeliveryDate;
            BookTitles            = order.LineItems.Select(x => x.ChosenBook.Title).ToList();
            PossibleDeliveryDates = new SelectList(FormPossibleDeliveryDates(DateTime.Today));
            var selected = PossibleDeliveryDates.FirstOrDefault(x => x.Text == NewDeliveryDate.ToString("d"));

            if (selected != null)
            {
                selected.Selected = true;
            }
        }