/// <summary>
        /// This validates the input and if OK creates
        /// an order and calls the _dbAccess to add to orders
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>returns an Order. Will be null if there are errors</returns>
        public Order Action(PlaceOrderInDto dto)                    //#D
        {                                                           //#E
            if (!dto.LineItems.Any())                               //#E
            {                                                       //#E
                AddError("No items in your basket.");               //#E
                return(null);                                       //#E
            }                                                       //#E

            var itemsDict =                                         //#F
                            _dbAccess.FindItemsByIdsWithPriceOffers //#F
                                (dto.LineItems.Select(x => x.SelectedItem.Key));

            var order = new Order                             //#G
            {                                                 //#G
                CustomerKey  = dto.Customer.Key,              //#G
                EmployeeKey  = dto.Employee.Key,
                OrderedItems =                                //#G
                               FormLineItemsWithErrorChecking //#G
                                   (dto.LineItems, itemsDict) //#G
            };                                                //#G

            if (!HasErrors)                                   //#H
            {
                _dbAccess.Add(order);                         //#H
            }
            return(HasErrors ? null : order);                 //#I
        }
Exemple #2
0
        /// <summary>
        /// This validates the input and if OK creates
        /// an order and calls the _dbAccess to add to orders
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>returns an Order. Will be null if there are errors</returns>
        public Order BizAction(PlaceOrderInDto dto)
        {
            if (!dto.AcceptTAndCs)
            {
                AddError("You must accept the T&Cs to place an order.");
                return(null);
            }
            if (!dto.LineItems.Any())
            {
                AddError("No items in your basket.");
                return(null);
            }

            var booksDict = _dbAccess.FindBooksByIdsWithPriceOffers
                                (dto.LineItems.Select(x => x.BookId));
            var order = new Order
            {
                CustomerName         = dto.UserId,
                ExpectedDeliveryDate = DateTime.Today.AddDays(5),
                LineItems            = FormLineItemsWithErrorChecking(dto.LineItems, booksDict)
            };

            if (!HasErrors)
            {
                _dbAccess.Add(order);
            }

            return(HasErrors ? null : order);
        }
Exemple #3
0
        /// <summary>
        /// This validates the input and if OK creates
        /// an order and calls the _dbAccess to add to orders
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>returns an Order. Will be null if there are errors</returns>
        public Order Action(PlaceOrderInDto dto)                       //#D
        {
            if (!dto.AcceptTAndCs)                                     //#E
            {                                                          //#E
                AddError(                                              //#E
                    "You must accept the T&Cs to place an order.");    //#E
                return(null);                                          //#E
            }                                                          //#E
            if (!dto.LineItems.Any())                                  //#E
            {                                                          //#E
                AddError("No items in your basket.");                  //#E
                return(null);                                          //#E
            }                                                          //#E

            var booksDict =                                            //#F
                            _dbAccess.FindBooksByIdsWithPriceOffers    //#F
                                (dto.LineItems.Select(x => x.BookId)); //#F
            var order = new Order                                      //#G
            {                                                          //#G
                CustomerName = dto.UserId,                             //#G
                LineItems    =                                         //#G
                               FormLineItemsWithErrorChecking          //#G
                                   (dto.LineItems, booksDict)          //#G
            };                                                         //#G

            if (!HasErrors)                                            //#H
            {
                _dbAccess.Add(order);                                  //#H
            }
            return(HasErrors ? null : order);                          //#I
        }
Exemple #4
0
        public Order Action(PlaceOrderInDto dto)
        {
            if (!dto.AcceptTAndCs)
            {
                AddError("You must accept the T&Cs to place an order.");
                return(null);
            }

            if (dto.LineItems.Count == 0)
            {
                AddError("No items in your basket.");
                return(null);
            }

            var bookIds = dto.LineItems.Select(lineItem => lineItem.BookId);
            //to present the data as an in-memory set(in this case, a dictionary)
            var booksDict = dbAccess.FindBooksByIdsWithPriceOffers(bookIds);
            var order     = new Order
            {
                CustomerName = dto.UserId,
                LineItems    = FormLineItemsWithErrorChecking(dto.LineItems, booksDict)
            };

            if (!HasErrors)
            {
                dbAccess.Add(order);
            }

            return(HasErrors ? null : order);
        }
        /// <summary>
        /// This validates the input and if OK creates
        /// an order and calls the _dbAccess to add to orders
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>returns an Order. Will be null if there are errors</returns>
        public Order BizAction(PlaceOrderInDto dto)
        {
            if (!dto.AcceptTAndCs)
            {
                AddError("You must accept the T&Cs to place an order.");
                return(null);
            }

            var bookOrders  = dto.CheckoutLineItems.Select(x => _dbAccess.BuildBooksDto(x.BookId, x.NumBooks));
            var orderStatus = Order.CreateOrderFactory(dto.UserId, DateTime.Today.AddDays(5), bookOrders);

            CombineErrors(orderStatus);

            if (!HasErrors)
            {
                _dbAccess.Add(orderStatus.Result);
            }

            return(orderStatus.Result);
        }
Exemple #6
0
        public Part1ToPart2Dto Action(PlaceOrderInDto dto)
        {
            if (!dto.AcceptTAndCs)
            {
                AddError("You must accept the T&Cs to place an order.");
            }

            if (dto.LineItems.Count == 0)
            {
                AddError("No items in your basket.");
            }

            Order order = new Order {
                CustomerName = dto.UserId
            };

            if (!HasErrors)
            {
                dbAccess.Add(order);
            }

            return(new Part1ToPart2Dto(dto.LineItems, order));
        }
Exemple #7
0
        public Part1ToPart2Dto BizAction(PlaceOrderInDto dto)
        {
            if (!dto.AcceptTAndCs)
            {
                AddError("You must accept the T&Cs to place an order.");
            }

            if (!dto.LineItems.Any())
            {
                AddError("No items in your basket.");
            }

            var order = new Order
            {
                CustomerName = dto.UserId
            };

            if (!HasErrors)
            {
                _dbAccess.Add(order);
            }

            return(new Part1ToPart2Dto(dto.LineItems.ToImmutableList(), order));
        }