Error to create New JobSite

Hello this error please help

Hello. You’re trying to save a jobsite with a duplicate name. You should check the business rules as well as trap excpetions when saving. Full examples on how to do this are here:

Hello, I do not know if you can appreciate, but there is no broken rule, I am using the validation that you mention in the link that you provided and the validation happens correctly, ie IsSavable = true, neither the name nor the code of the project that I am trying to save this created in quantify, DOES NOT DUPLICATE. Please I require your help
This is the code I am running

       // Guid LocationId;
        string Code = "PY0999";
        string Name = "SAP";
        string From = "2016-12-01 00:00:00.000";
        string To = "2035-01-01 00:00:00.000";
        string CustomerNumber = "C00100";
        //string CustomerName = "";
        //string Billing = "";
        //string Bussines = "";
        //string Shipping = "";
        string Active = "Y";
        Guid BpId;

        BusinessPartner BP = BusinessPartner.GetBusinessPartnerByNumber(CustomerNumber);
        StockingLocationList jobs = StockingLocationList.GetJobsites(false, JobTreeNodeDisplayType.Name, Guid.Empty);

        var product = jobs.FirstOrDefault(prod => prod.Number == Code);
        BpId = BP.BusinessPartnerID;

        bool Act;
        //string Active = null;
        if (Active == "Y") { Act = true; } else { Act = false; };

        if (product == null)

            var NewBp = BusinessPartner.NewBusinessPartner(PartnerTypes.Customer);

            StockingLocation Add = StockingLocation.NewStockingLocation(PartnerTypes.JobSite,Guid.Empty);
            Add.Number = Code;
            Add.Name = Name;
            Add.CycleBeginDate = From;
            Add.CycleEndDate = To;
            Add.IsActive = Act;
            Add.BusinessPartnerID = BpId;
           Add.IsBillable = false;

            foreach (Avontus.Core.Validation.BrokenRule rule in Add.BrokenRulesCollection)
                if (rule.Property == "Name")
                    // Fix the name here

            if (Add.IsSavable)
                // Save



            StockingLocation Ups = StockingLocation.GetStockingLocation(Name,false);

            Ups.Number = Code;
            Ups.Name = Name;
            Ups.CycleBeginDate = From;
            Ups.CycleEndDate = To;
            Ups.IsActive = Act;
            Ups.BusinessPartnerID = BpId;


Hello. Yes, totally makes sense that there is no broken rule upon save. Your code isn’t trapping the exception upon save. The rule check on your error doesn’t occur until you save. This is shown in the sample code. Once you add the sample code you’ll see that you’re trying to save a duplicate name.