Пример #1
0
        protected override void ModelToEntity(TransportOrdersModel model, TransportOrders entity, ActionTypes actionType)
        {
            if (actionType == ActionTypes.Add && model.customerSelectType == 2)
            {
                var customer = new Customers()
                {
                    Number = model.customerNumber,
                    Name   = model.newCustomerName,
                    Street = model.customerStreet,
                    City   = model.customerCity,
                    Zip    = model.customerZip,
                    Phone  = model.customerPhone,
                    Fax    = model.customerFax,
                    Email  = model.customerEmail
                };

                if (!model.isOffer)
                {
                    var lastCustomerNumber = customerManager.GetEntities().Max(o => o.Number);
                    customer.Number = lastCustomerNumber + 1;
                }

                customerManager.AddEntity(customer);
                customerManager.SaveChanges();
                entity.CustomerId = customer.Id;
            }
            else
            {
                entity.CustomerId             = model.customerId;
                entity.CommunicationPartnerId = model.communicationPartnerId > 0 ? model.communicationPartnerId : (int?)null;
            }

            entity.DeliveryPlace       = model.deliveryPlace;
            entity.Street              = model.street;
            entity.Zip                 = model.zip;
            entity.City                = model.city;
            entity.Comment             = model.comment;
            entity.OrderDate           = model.orderDate;
            entity.OrderedFrom         = model.orderedFrom;
            entity.OrderNumber         = model.orderNumber;
            entity.Discount            = model.discount;
            entity.BillTillDate        = model.billTillDate;
            entity.IsOffer             = model.isOffer;
            entity.CustomerOrderNumber = model.customerOrderNumber;

            if (entity.IsNew())
            {
                entity.CreateDate = DateTime.Now;
                entity.Status     = (int)OrderStatusTypes.Open;
            }
        }
Пример #2
0
        protected override void ModelToEntity(OrdersModel model, Orders entity, ActionTypes actionType)
        {
            if (actionType == ActionTypes.Add && model.customerSelectType == 2)
            {
                var customer = new Customers()
                {
                    Number = model.customerNumber,
                    Name   = model.newCustomerName,
                    Street = model.customerStreet,
                    City   = model.customerCity,
                    Zip    = model.customerZip,
                    Phone  = model.customerPhone,
                    Fax    = model.customerFax,
                    Email  = model.customerEmail,
                    IsProspectiveCustomer = model.isOffer,
                    WithTaxes             = true, //TODO
                };

                if (!model.isOffer)
                {
                    var lastCustomerNumber = customerManager.GetEntities().Max(o => o.Number);
                    customer.Number = lastCustomerNumber + 1;
                }

                customerManager.AddEntity(customer);
                customerManager.SaveChanges();
                entity.CustomerId = customer.Id;
            }
            else
            {
                entity.CustomerId             = model.customerId;
                entity.CommunicationPartnerId = model.communicationPartnerId > 0 ? model.communicationPartnerId : (int?)null;
            }

            entity.Street      = model.street;
            entity.Zip         = model.zip;
            entity.City        = model.city;
            entity.Comment     = model.comment;
            entity.OrderNumber = model.orderNumber;
            entity.AutoBill    = model.autoBill;
            entity.Discount    = model.discount;
            entity.IsOffer     = model.isOffer;

            if (entity.IsNew())
            {
                entity.CreateDate = DateTime.Now;
                entity.Status     = (int)OrderStatusTypes.Open;
                entity.Positions  = new List <Positions>();

                //TODO replace with template positions
                //foreach (var additionalCost in additionalCostsManager.GetEntities(o => o.Automatic).ToList())
                //{
                //    entity.Positions.Add(new Positions()
                //    {
                //        Orders = entity,
                //        Amount = 1,
                //        Price = additionalCost.Price,
                //        AdditionalCosts = additionalCost,
                //        IsSellOrder = false,
                //    });
                //}
            }
        }