示例#1
0
        public IHttpActionResult Put(ProductsModel model)
        {
            var product = manager.GetById(model.Id);

            var newProduct = new Products()
            {
                Comment             = product.Comment,
                ProductTypeId       = product.ProductTypeId,
                Price               = product.Price,
                ProceedsAccountId   = product.ProceedsAccountId,
                Number              = String.Empty,
                ProductMaterialRsps = new List <ProductMaterialRsp>(),
                CreateDate          = DateTime.Now,
                ChangeDate          = DateTime.Now,
            };

            manager.AddEntity(newProduct);

            foreach (var material in product.ProductMaterialRsps.Where(o => !o.DeleteDate.HasValue).ToList())
            {
                var newPosition = new ProductMaterialRsp()
                {
                    Amount     = material.Amount,
                    MaterialId = material.MaterialId,
                    Products   = newProduct
                };

                //positionManager.AddEntity(newPosition);
                newProduct.ProductMaterialRsps.Add(newPosition);
            }

            manager.SaveChanges();

            return(Ok(new { id = newProduct.Id }));
        }
        public IHttpActionResult Put(ProductsModel model)
        {
            var product = manager.GetById(model.Id);

            var newProduct = new Products()
            {
                Comment = product.Comment,
                ProductTypeId = product.ProductTypeId,
                Price = product.Price,
                ProceedsAccountId = product.ProceedsAccountId,
                Number = String.Empty,
                ProductMaterialRsps = new List<ProductMaterialRsp>(),
                CreateDate = DateTime.Now,
                ChangeDate = DateTime.Now,
            };
            
            manager.AddEntity(newProduct);

            foreach(var material in product.ProductMaterialRsps.Where(o => !o.DeleteDate.HasValue).ToList())
            {
                var newPosition = new ProductMaterialRsp()
                {
                    Amount = material.Amount,
                    MaterialId = material.MaterialId,
                    Products = newProduct
                };

                //positionManager.AddEntity(newPosition);
                newProduct.ProductMaterialRsps.Add(newPosition);
            }

            manager.SaveChanges();

            return Ok(new { id = newProduct.Id });
        }
 protected void ExtraEntityToModel(ProductMaterialRsp entity, ProductMaterialRspModel model)
 {
     model.materialName = entity.Materials.Name;
 }