Example #1
0
        public IHttpActionResult Put(OrdersModel model)
        {
            var order = manager.GetById(model.Id);

            var newOrder = new Orders()
            {
                AutoBill = order.AutoBill,
                City     = order.City,
                Comment  = order.Comment,
                CommunicationPartnerId = order.CommunicationPartnerId,
                CustomerId             = order.CustomerId,
                Discount    = order.Discount,
                Street      = order.Street,
                Status      = (int)OrderStatusTypes.Open,
                Zip         = order.Zip,
                IsOffer     = false,
                OrderNumber = numberProvider.GetNextOrderNumber(),
                Positions   = new List <Positions>(),
                CreateDate  = DateTime.Now,
                ChangeDate  = DateTime.Now,
            };

            manager.AddEntity(newOrder);

            foreach (var position in order.Positions.Where(o => o.MaterialId.HasValue && !o.DeleteDate.HasValue).ToList())
            {
                var newPosition = new Positions()
                {
                    MaterialId         = position.MaterialId.Value,
                    IsAlternative      = position.IsAlternative,
                    IsMaterialPosition = position.IsMaterialPosition,
                    Amount             = position.Amount,
                    Price       = position.Price,
                    PaymentType = position.PaymentType,
                    Orders      = newOrder
                };

                positionManager.AddEntity(newPosition);
                newOrder.Positions.Add(newPosition);
            }

            manager.SaveChanges();

            return(Ok(new { id = newOrder.Id }));
        }