public async Task <DiseaseResponse> GetById(int id) { var disease = await _diseaseRepository.GetById(id); if (disease == null) { string errorMessage = "Disease not found."; Log.Error(errorMessage); return(new DiseaseResponse(errorMessage)); } return(new DiseaseResponse(DiseaseMapper.Map(disease))); }
public PersonsDiseaseQuery(IPersonRepository personRepository, IDiseaseRepository diseaseRepository, IPersonalDiseasesRepository pdRepository) { Name = "PersonsDiseaseQuery"; Field <PersonsType>( "person", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "Id" }), resolve: context => personRepository.GetById(context.GetArgument <int>("Id")) ); Field <ListGraphType <PersonsType> >( "persons", "Returns list of persons", resolve: context => personRepository.GetAll() ); Field <DiseasesType>( "disease", arguments: new QueryArguments(new QueryArgument <IntGraphType> { Name = "Id" }), resolve: context => diseaseRepository.GetById(context.GetArgument <int>("Id")) ); Field <ListGraphType <DiseasesType> >( "diseases", "returns list of disease", resolve: context => diseaseRepository.GetAll() ); Field <ListGraphType <PersonalDiseasesType> >( "personsDiseases", "returns list of all persons with diseases", resolve: context => pdRepository.GetAll() ); }
public PersonalDiseasesType(IDiseaseRepository diseaseRepository, IPersonRepository personRepository, IPersonalDiseasesRepository pdRepository) { Field(x => x.Id, type: typeof(IdGraphType)).Description("Personal Disease Id"); Field(x => x.PersonId, type: typeof(IdGraphType)).Description("Person Id"); Field(x => x.DiseaseId, type: typeof(IdGraphType)).Description("Disease Id"); Field(x => x.DateOfGetting).Description("Date of Getting It"); FieldAsync <DiseasesType, Disease>("disease", resolve: ctx => { return(diseaseRepository.GetById(ctx.Source.DiseaseId)); }); FieldAsync <PersonsType, Person>("person", resolve: ctx => { return(personRepository.GetById(ctx.Source.PersonId)); }); }
public Disease GetDiseaseById(Guid id) { return(_repository.GetById(id)); }
public PersonsDiseaseMutation(IPersonRepository personRepository, IDiseaseRepository diseaseRepository, IPersonalDiseasesRepository pdRepository) { Name = "PersonsDiseaseMutation"; #region Person FieldAsync <PersonsType>( "createPerson", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PersonsInputType> > { Name = "person" } ), resolve: async context => { var personInput = context.GetArgument <Person>("person"); await personRepository.Add(personInput); return($"Person has been created succesfully."); } ); FieldAsync <PersonsType>( "updatePerson", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PersonsInputType> > { Name = "person" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "personId" } ), resolve: async context => { var personInput = context.GetArgument <Person>("person"); var personId = context.GetArgument <int>("personId"); var personInfoRetrived = await personRepository.GetById(personId); if (personInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Person info.")); return(null); } personInfoRetrived.Name = personInput.Name; personInfoRetrived.DateOfBirth = personInput.DateOfBirth; personInfoRetrived.Address = personInput.Address; personInfoRetrived.Gender = personInput.Gender; await personRepository.Update(personInfoRetrived); return($"Person ID {personId} with Name {personInfoRetrived.Name} has been updated succesfully."); } ); FieldAsync <StringGraphType>( "deletePerson", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "personId" }), resolve: async context => { var personId = context.GetArgument <int>("personId"); var personInfoRetrived = await personRepository.GetById(personId); if (personInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Person info.")); return(null); } await personRepository.Delete(personId); return($"Person ID {personId} with Name {personInfoRetrived.Name} has been deleted succesfully."); } ); #endregion #region Disease FieldAsync <DiseasesType>( "createDisease", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <DiseasesInputType> > { Name = "disease" } ), resolve: async context => { var diseaseInput = context.GetArgument <Disease>("disease"); await diseaseRepository.Add(diseaseInput); return($"Disease has been created succesfully."); } ); FieldAsync <DiseasesType>( "updateDisease", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <DiseasesInputType> > { Name = "disease" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "diseaseId" } ), resolve: async context => { var diseaseInput = context.GetArgument <Disease>("disease"); var diseaseId = context.GetArgument <int>("diseaseId"); var diseaseInfoRetrived = await diseaseRepository.GetById(diseaseId); if (diseaseInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Disease info.")); return(null); } diseaseInfoRetrived.DiseaseName = diseaseInput.DiseaseName; diseaseInfoRetrived.Description = diseaseInput.Description; await diseaseRepository.Update(diseaseInfoRetrived); return($"Disease ID {diseaseId} has been updated succesfully."); } ); FieldAsync <StringGraphType>( "deleteDisease", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "diseaseId" }), resolve: async context => { var diseaseId = context.GetArgument <int>("diseaseId"); var diseaseInfoRetrived = await diseaseRepository.GetById(diseaseId); if (diseaseInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Disease info.")); return(null); } await diseaseRepository.Delete(diseaseId); return($"Disease ID {diseaseId} with Name {diseaseInfoRetrived.DiseaseName} has been deleted succesfully."); } ); #endregion #region Personal Diseases FieldAsync <PersonalDiseasesType>( "addPersonalDisease", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <PersonalDiseasesInputType> > { Name = "personalDisease" }), resolve: async context => { var personalDisease = context.GetArgument <PersonalDisease>("personalDisease"); await pdRepository.Add(personalDisease); return($"Personal disease has been created succesfully."); } ); FieldAsync <PersonalDiseasesType>( "updatePersonalDisease", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <DiseasesInputType> > { Name = "personalDisease" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "personalDiseaseId" } ), resolve: async context => { var pdInput = context.GetArgument <PersonalDisease>("personalDisease"); var pdId = context.GetArgument <int>("personalDiseaseId"); var pdInfoRetrived = await pdRepository.GetById(pdId); if (pdInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Personal Disease info.")); return(null); } pdInfoRetrived.DiseaseId = pdInput.DiseaseId; pdInfoRetrived.PersonId = pdInput.PersonId; pdInfoRetrived.DateOfGetting = pdInput.DateOfGetting; await pdRepository.Update(pdInfoRetrived); return($"Personal Disease ID {pdId} has been updated succesfully."); } ); FieldAsync <StringGraphType>( "deletePersonalDisease", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "personalDisease" }), resolve: async context => { var pdId = context.GetArgument <int>("personalDisease"); var pdInfoRetrived = await pdRepository.GetById(pdId); if (pdInfoRetrived == null) { context.Errors.Add(new ExecutionError("Couldn't find Personal Disease info.")); return(null); } await pdRepository.Delete(pdId); return($"Personal Disease ID {pdId} has been deleted succesfully."); } ); #endregion }