Beispiel #1
0
        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 }));
        }
Beispiel #2
0
        public IActionResult EditVendor([FromBody] VendorForm form)
        {
            var error  = new Error();
            var vendor = _vendorManager.UpdateVendor(form.MapToCore(), ref error);

            if (error.ErrorCode != ErrorCode.OKAY)
            {
                return(BadRequest(error.Message));
            }

            return(Ok(VendorDetails.MapFromObject(vendor, _responseGenerator)));
        }