Skip to content

Commit

Permalink
ValidateVendor should handle the case when we want to remove the Vend…
Browse files Browse the repository at this point in the history
…or by setting it to 0 rather than throwing an error that such a vendor does not exist.
  • Loading branch information
poyker committed Feb 19, 2017
1 parent e563df9 commit ab5ee1d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Nop.Plugin.Api/Attributes/ValidateVendor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public override void Validate(object instance)

if (instance != null && int.TryParse(instance.ToString(), out vendorId))
{
Vendor vendor = VendorService.GetVendorById(vendorId);

if (vendor == null)
if (vendorId > 0)
{
_errors.Add("Invalid vendor id", "Non existing vendor");
Vendor vendor = VendorService.GetVendorById(vendorId);

if (vendor == null)
{
_errors.Add("Invalid vendor id", "Non existing vendor");
}
}
// TODO: validate that the vendorId is an existing vendor.
}
// The type validation happens in the model binder automatically so we don't need to set an error here.
}

public override Dictionary<string, string> GetErrors()
Expand Down

0 comments on commit ab5ee1d

Please sign in to comment.