/// <summary>
        /// Dodjeljuje izvodaca radova na popravak ili odrzavanje
        /// </summary>
        /// <param name="contractor">izvodac radova</param>
        /// <param name="maintenance">popravak ili odrzavanje</param>
        public void SetContractorForMaintenance(Contractor contractor, Maintenance maintenance)
        {
            var errors = new RulesException<BuildingManager>();

            if(!contractors.Contains(contractor)) {
                errors.ErrorForModel("Contractor is not working for BuildingManager, so it's invalid.");
            }

            if (!Equals(maintenance.BuildingManager)) {
                errors.ErrorForModel("This BuildingManager is not in charge of a builing in given maintenance.");
            }

            if (!contractor.RepairServices.Contains(maintenance.ServiceType)) {
                errors.ErrorForModel("This Contractor can't do needed service.");
            }

            if(errors.Errors.Any()) {
                throw errors;
            }

            maintenance.SetContractor(contractor);
        }
示例#2
0
        /// <summary>
        /// Provjerava da li je trenutni objekt u ispravnom stanju
        /// </summary>
        public void IsValid()
        {
            var errors = new RulesException<Person>();

            if(!isOibValid()) {
                errors.ErrorFor(x => x.Oib, "Oib is not valid.");
            }

            if(errors.Errors.Any()) {
                throw errors;
            }
        }