public IActionResult CreateVendor([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)); } } var vendorId = _vendorManager.CreateVendor(form.MapToCore(), ref error); if (error.ErrorCode != ErrorCode.OKAY) { return(BadRequest(error.Message)); } return(Ok(new { VendorId = vendorId })); }