Beispiel #1
0
        private async void Submit()
        {
            var hasValidationErrors = ValidateProperties(new Dictionary <string, object>()
            {
                { nameof(OrderID), OrderID },
                { nameof(OrderDate), OrderDate },
                { nameof(OrderTime), OrderTime },
                { nameof(Company), Company },
                { nameof(Symbol), Symbol },
                { nameof(OrderTotal), OrderTotal },
                { nameof(Freight), Freight },
                { nameof(Status), Status },
                { nameof(ShipperName), ShipperName },
                { nameof(ShipperPhone), ShipperPhone },
                { nameof(ShipTo), ShipTo }
            });

            if (hasValidationErrors)
            {
                return;
            }

            await _sampleDataService.SaveOrderAsync(new SampleOrder()
            {
                OrderID      = OrderID,
                OrderDate    = new DateTime(OrderDate.Year, OrderDate.Month, OrderDate.Day, OrderTime.Hours, OrderTime.Minutes, OrderTime.Seconds),
                ShipperName  = ShipperName,
                ShipperPhone = ShipperPhone,
                Company      = Company,
                ShipTo       = ShipTo,
                OrderTotal   = double.Parse(OrderTotal),
                Status       = Status,
                Freight      = double.Parse(Freight),
                SymbolCode   = Symbol
            });

            // Set default values
            OrderID      = default;
            OrderDate    = DateTime.Now;
            OrderTime    = DateTime.Now.TimeOfDay;
            ShipperName  = string.Empty;
            ShipperPhone = string.Empty;
            Company      = string.Empty;
            ShipTo       = string.Empty;
            OrderTotal   = default;
            Freight      = default;
            Status       = StatusValues.First();
            Symbol       = SymbolValues.First();
            ClearErrors();
        }