public IActionResult EditMaterials([FromBody] VendorForm form) { var error = new Error(); var materials = new List <MaterialVendor>(); foreach (var material in form.NewMaterial) { material.VendorId = form.VendorId; materials.Add(material.MapToCore()); } foreach (var material in form.KnownMaterial) { material.VendorId = form.VendorId; materials.Add(material.MapToCore()); } //Validate materials foreach (var material in materials) { _materialManager.ValidateMaterial(material, ref error); if (error.ErrorCode != ErrorCode.OKAY) { return(BadRequest(error.Message)); } } _materialManager.AddMaterials(materials, ref error); return(GetVendorDetails(form.VendorId)); }