public void Log(Exception exception)
        {
            var exceptionToLog = new ExceptionLog
            {
                Date           = _dateTimeFacade.GetCurrentTime(),
                Message        = exception.Message,
                InnerException = exception.InnerException?.Message,
                StackTrace     = exception.StackTrace
            };

            _candyStoreRepository.Insert(exceptionToLog);
        }
Exemple #2
0
        public string GetReceiptText()
        {
            _stringBuilderFacade.AppendLine("Candy Store Receipt");
            _stringBuilderFacade.AppendLine("\n");
            _stringBuilderFacade.AppendLine($"Order: {View.OrderId.ToString()}");

            var purchasedProducts = (from order in _candyStoreRepository.GetAll <Order>().Where(x => x.OrderID == View.OrderId)
                                     join orderDetail in _candyStoreRepository.GetAll <OrderDetails>()
                                     on order.OrderID equals orderDetail.OrderId
                                     into joinedOrderDetails
                                     from joinedOrderDetail in joinedOrderDetails
                                     join product in _candyStoreRepository.GetAll <Product>()
                                     on joinedOrderDetail.ProductId equals product.ProductID
                                     select new
            {
                Product = product,
                Quantity = joinedOrderDetail.ProductQuantity
            })
                                    .ToDictionary(x => x.Product, x => x.Quantity);

            foreach (var item in purchasedProducts)
            {
                string currentLine = $"{item.Key.Name}  ${item.Key.Price:f2} x {item.Value}    ${item.Value * item.Key.Price:f2}";
                _stringBuilderFacade.AppendLine(currentLine);
            }

            var orderInDb = _candyStoreRepository.GetAll <Order>()
                            .FirstOrDefault(x => x.OrderID == View.OrderId);

            _stringBuilderFacade.AppendLine($"\nTotal price: {orderInDb.TotalPrice.ToString("0.00" + "$")}");

            _stringBuilderFacade.AppendLine($"\nCustomer: {orderInDb.Customer.FirstName} {orderInDb.Customer.LastName}");
            _stringBuilderFacade.AppendLine($"\nDate: {_dateTimeFacade.GetCurrentTime()}");

            return(_stringBuilderFacade.ToString());
        }