protected void SetupSecondaryData(DbContext db)
        {
            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)
            {
                throw new InvalidOperationException("I could not find the order you asked for.");
            }

            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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// This is called by the BizRunner’s GetOriginal or ResetDto methods.
        /// It sets up the presentation layer properties
        /// </summary>
        /// <param name="repository">The repository to allow access to the database</param>
        /// <param name="status">The BizActionStatus so you can register errors</param>
        protected override void SetupSecondaryData(object repository, IStatusGenericHandler 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 = ((NonEfRepo)repository).GetOrder(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;
            }
        }