public IActionResult Get(int id) { var unitType = _unitTypeService.Get(id); if (unitType == null) { return(NotFound()); } return(Ok(unitType.ToApiModel())); }
public NewUnitValidator( ICompanyService companyService, ITranslationsService translationsService, IUnitService unitService, IUnitTypeService unitTypeService) : base(companyService, translationsService) { RuleFor(x => x.ParentUnitId).Must(x => { if (x.HasValue) { var unit = unitService.Get(x.Value); return(unit.Data != null); } return(true); }).WithMessage(translationsService.GetTranslationByKey("validations.unitNotFound")); RuleFor(x => x.ParentUnitId).Must(x => { if (x.HasValue) { var unit = unitService.Get(x.Value); if (unit.Data != null) { return(unit.Data.IsContainer); } } return(true); }).WithMessage(translationsService.GetTranslationByKey("validations.parentUnitIsNotContainer")); RuleFor(x => x.TypeId).NotNull().WithMessage(translationsService.GetTranslationByKey("validations.required")); RuleFor(x => x.TypeId).Must(x => { if (x.HasValue) { var type = unitTypeService.Get(x.Value); return(type.Data != null); } return(true); }).WithMessage(translationsService.GetTranslationByKey("validations.unitTypeNotFound")); RuleFor(x => x.Name).NotEmpty().WithMessage(translationsService.GetTranslationByKey("validations.required")); RuleFor(x => x.Name).Must(x => !unitService.Get(n => n.Name.Equals(x)).Data.Any()) .WithMessage(translationsService.GetTranslationByKey("validations.duplicateName")); }