Exemple #1
0
        private async Task <bool> SubmitOrderTransactionAsync()
        {
            string errorMessage = string.Empty;

            try
            {
                await _orderService.ProcessOrderAsync(_order);

                await _shoppingCartRepository.ClearCartAsync();

                _navigationService.Navigate("OrderConfirmation", Guid.NewGuid().ToString());
                return(true);
            }
            catch (ModelValidationException mvex)
            {
                errorMessage = string.Format(CultureInfo.CurrentCulture, _resourceLoader.GetString("GeneralServiceErrorMessage"), Environment.NewLine, mvex.Message);
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorProcessingOrder"));
            }

            return(false);
        }
Exemple #2
0
        public async Task <Order> CreateOrderAsync(Order order)
        {
            var customLunch = _cartRepository.GetSessionLunchIfNotEmpty(order.BookingId);

            if (customLunch != null)
            {
                _lunchRep.SaveLunch(order.BookingId);
                _cartRepository.AddCateringToOrder(customLunch);
            }

            order.BookingId = order.BookingId ?? _cartRepository.GetSessionCartId();

            order.Cuit             = _cartRepository.GetCuit(order.BookingId);
            order.OrderTotal       = _cartRepository.GetTotal(order.BookingId);
            order.TotalInStore     = _cartRepository.GetTotalInStore(order.BookingId);
            order.Discount         = _cartRepository.GetDiscount(order.BookingId);
            order.DeliveryAddress  = _cartRepository.GetDelivery(order.BookingId);
            order.CustomerComments = _cartRepository.GetComments(order.BookingId)?.Comments;
            order.PreparationTime  = _cartRepository.GetPreparationTime(order.BookingId);
            order.OrderPlaced      = _calendarRepository.LocalTime();
            order.PickedUp         = false;

            var pickUpTime = _cartRepository.GetPickUpDate(order.BookingId);

            order.PickUpTimeFrom           = pickUpTime.From;
            order.TimeLeftUntilStoreCloses = pickUpTime.To;
            order.PickUpTime = order.PickUpTimeFrom;// _calendarRepository.GetPickupEstimate(order.PreparationTime);

            _appDbContext.Orders.Add(order);
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingItems = _cartRepository.GetItems(order.BookingId);

            _appDbContext.OrderDetails.AddRange(shoppingItems.Select(x => new OrderDetail()
            {
                Amount  = x.Amount,
                PieId   = x.Pie.PieId,
                OrderId = order.OrderId,
                Price   = x.Pie.Price
            }));
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingProductItems = _cartRepository.GetCatalogItems(order.BookingId);

            _appDbContext.OrderCatalogItems.AddRange(shoppingProductItems.Select(x => new OrderCatalogItem()
            {
                Amount    = x.Amount,
                Price     = x.Product.Price,
                OrderId   = order.OrderId,
                ProductId = x.Product.ProductId,
                Product   = x.Product
            }));
            _appDbContext.SaveChanges();

            /**********************/

            var shoppingLunches = _cartRepository.GetShoppingCaterings(order.BookingId).Select(x => _mapper.Map <ShoppingCartComboCatering, OrderCatering>(x)).ToArray();

            foreach (var lunch in shoppingLunches)
            {
                lunch.Order   = order;
                lunch.OrderId = order.OrderId;
            }
            _appDbContext.OrderCaterings.AddRange(shoppingLunches);
            _appDbContext.SaveChanges();

            /**********************/

            await _cartRepository.ClearCartAsync(order.BookingId);

            return(order);
        }
 public Task ClearCartAsync()
 {
     return(shoppingCartRepository.ClearCartAsync());
 }