public Region Action(NameOnlyViewModel dto) { var region = new Region() { Nombre = dto.Nombre }; try { var result = _dbAccess.GetRegion(dto.Nombre); if (result != null) { throw new InvalidOperationException(); } } catch (InvalidOperationException) { AddError($"Ya existe la ciudad {region.Nombre}."); } if (!HasErrors) { _dbAccess.Add(region); } return(HasErrors ? null : region); }
public long RegisterPais(PaisCommand cmd, out IImmutableList <ValidationResult> errors) { if (cmd.RegionName != null) { cmd.Region = _regionDbAccess.GetRegion(cmd.RegionName); } var pais = _runnerPais.RunAction(cmd); if (_runnerPais.HasErrors) { errors = _runnerPais.Errors; return(-1); } errors = null; return(pais.PaisID); }