public override Model.Order ToModel()
 {
     return(new Model.BreadOrder()
     {
         Id = Id,
         CustomerName = CustomerName,
         CustomerAddress = CustomerAddress,
         OrderLines = OrderLines.Select(o => o.ToModel()).ToList()
     });
 }
Esempio n. 2
0
 public Order MapToOrder()
 {
     return(new Order()
     {
         OrderId = OrderId,
         CustomerId = CustomerId,
         OrderDate = OrderDate,
         OrderNote = Notes,
         OrderLines = OrderLines.Select(l => l.MapToLine()).ToList()
     });
 }
Esempio n. 3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (OrderLines.Any(orderLine => orderLine.Quantity <= 0))
            {
                yield return(new ValidationResult(
                                 "Quantity should be greater than 0.",
                                 new[] { "OrderLines" }
                                 ));
            }

            if (OrderLines.Select(orderLine => orderLine.Quantity).Sum() <= 0)
            {
                yield return(new ValidationResult(
                                 "Total quantity should be greater than 0.",
                                 new[] { "OrderLines" }
                                 ));
            }
        }
 private void CalculateShippingCost()
 {
     ShippingCost = _costCalculatorService.CalculateShippingPrice(OrderLines.Select(x => x.Product).ToList(), ShippingAddress);
 }
Esempio n. 5
0
 private void CalculateOrderTotalPrice()
 {
     OrderHeader.OrderTotalPrice = OrderLines.Select(x => x.ItemTotalPrice).Sum();
 }
        public WaybillDetails(uint id)
        {
            DisplayName = "Детализация накладной";
            this.id     = id;
            InitFields();
            CurrentWaybillLine = CurrentLine.OfType <WaybillLine>().ToValue();

            Settings.Subscribe(_ => Calculate());
            CurrentTax.Subscribe(v => {
                if (Lines.Value == null)
                {
                    return;
                }
                if (v == null || v.Value == -1)
                {
                    Lines.Value.Filter = null;
                }
                else
                {
                    Lines.Value.Filter = o => ((WaybillLine)o).Nds == v.Value;
                }
            });
            Lines.Select(v => v == null
                                ? Observable.Empty <EventPattern <NotifyCollectionChangedEventArgs> >()
                                : v.ToCollectionChanged())
            .Switch()
            .Subscribe(e => {
                if (e.EventArgs.Action == NotifyCollectionChangedAction.Remove)
                {
                    e.EventArgs.OldItems.OfType <WaybillLine>().Each(l => Waybill.RemoveLine(l));
                }
                else if (e.EventArgs.Action == NotifyCollectionChangedAction.Add)
                {
                    e.EventArgs.NewItems.OfType <WaybillLine>().Each(l => Waybill.AddLine(l));
                }
            });
            OrderLines = CurrentWaybillLine
                         .Throttle(Consts.ScrollLoadTimeout, UiScheduler)
                         .Select(v => {
                if (v == null)
                {
                    return(new List <SentOrderLine>());
                }
                var lineId       = v.Id;
                var orderLineIds = Session.Query <WaybillOrder>().Where(l => l.DocumentLineId == lineId)
                                   .Select(l => (uint?)l.OrderLineId)
                                   .ToArray();
                var line = Session.Query <SentOrderLine>().FirstOrDefault(l => orderLineIds.Contains(l.ServerId));
                if (line != null)
                {
                    CurrentOrderLine.Value = line;
                    line.Order.Lines.Each(l => l.Configure(User));
                    return(line.Order.Lines.OrderBy(l => l.ProductSynonym).ToList());
                }
                return(new List <SentOrderLine>());
            })
                         .ToValue(CloseCancellation);
            EmptyLabelVisibility = OrderLines
                                   .Select(v => v == null || v.Count == 0 ? Visibility.Visible : Visibility.Collapsed)
                                   .ToValue();
            OrderDetailsVisibility = EmptyLabelVisibility
                                     .Select(v => v == Visibility.Collapsed ? Visibility.Visible :  Visibility.Collapsed)
                                     .ToValue();
        }