public DeviceModel Map(DeviceEntity source, DeviceModel destination) { destination.Id = source.Id; destination.DeviceId = source.DeviceId; destination.DeviceModelId = source.DeviceModelId; DeviceData.Model.DeviceModel deviceModel = deviceModelDataService.GetById(source.DeviceModelId); destination.Model = deviceModel != null ? mapper.Map <DeviceData.Model.DeviceModel, DeviceModelModel>(deviceModel) : null; return(destination); }
protected override async Task ValidateSave(DeviceModel device, ValidationResult validationResult) { if (string.IsNullOrEmpty(device.DeviceId)) { validationResult.AddError(nameof(DeviceModel.DeviceId), "The Device ID is required."); } else if (await repository.GetEntities <DeviceEntity>() .AnyAsync(x => x.DeviceId == device.DeviceId && x.Id != device.Id)) { validationResult.AddError(nameof(DeviceModel.DeviceId), "The Device ID already exists in the database."); } if (deviceModelDataService.GetById(device.DeviceModelId) == null) { validationResult.AddError(nameof(device.DeviceModelId), "No such device model."); } }