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 Post([FromBody] AddNewPositionModel model) { var term = termManager.GetById(model.termId); ClientTermViewModel result = null; var product = productManager.GetById(model.productId); var user = userManager.GetByLogin(model.Login); if (user != null && user.Token == model.Token && product != null && term != null) { var newPosition = new Positions() { Amount = 1, //TODO Description = product.Name, ProductId = product.Id, Price = product.Price, OrderId = term.OrderId, }; positionsManager.AddEntity(newPosition); var newTermPosition = new TermPositions() { TermId = term.Id, Amount = 1, //TODO Positions = newPosition, TermPositionMaterialRsps = new List <TermPositionMaterialRsp>() }; term.TermPositions.Add(newTermPosition); //add linked material to position foreach (var material in product.ProductMaterialRsps.Where(o => !o.DeleteDate.HasValue)) { newTermPosition.TermPositionMaterialRsps.Add(new TermPositionMaterialRsp() { Amount = material.Amount, MaterialId = material.MaterialId, TermPositions = newTermPosition }); } positionsManager.SaveChanges(); if (term != null) { result = TermViewModelHelper.ToModel(term, true, false); } return(Ok(result)); } return(BadRequest()); }
public ActionResult Get(int id) { return(GetStatusCodeResult(_productsManager.GetById(id))); }