public ConferenceMutation(TalksRepository talkRepository, SpeakersRepository speakersRepository) { FieldAsync <Talk>( "createTalk", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <TalkInput> > { Name = "talkInput" } ), resolve: async context => { var talk = context.GetArgument <Data.Entities.Talk>("talkInput"); //you can also validate return(await context.TryAsyncResolve(async c => await talkRepository.Add(talk))); }); FieldAsync <Speaker>( "createSpeaker", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <SpeakerInput> > { Name = "speakerInput" } ), resolve: async context => { var speaker = context.GetArgument <Data.Entities.Speaker>("speakerInput"); //you can also validate return(await context.TryAsyncResolve(async c => await speakersRepository.Add(speaker))); }); }
public async Task <SessionDetailsModel> CreateAsync(SessionCreateModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var session = Mapper.Map <Session>(model); // verify speaker id and audience id are valid var speaker = await SpeakersRepository.GetByIdAsync(session.SpeakerId); var audience = await AudiencesRepository.GetByIdAsync(session.AudienceId); if (speaker == null || audience == null) { throw new IndexOutOfRangeException(); } session.Speaker = speaker; session.Audience = audience; var created = await Repository.CreateAsync(session); await Audit.AuditCreatedAsync($"Session {session.Title} has been created"); return(Mapper.Map <SessionDetailsModel>(created)); }
// // GET: /Home/ public ActionResult Index() { SpeakersRepository repository = new SpeakersRepository(); var speakers = repository.GetAllSpeakers(); ViewBag.Speakers = speakers; return(View()); }
public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) { if (controllerName.ToLower().StartsWith("home")) { ISpeakerService service = new SpeakersRepository(); IController controller = new HomeController(service); return(controller); } IControllerFactory factory = new DefaultControllerFactory(); return(factory.CreateController(requestContext, controllerName)); }
public async Task <SessionDetailsModel> UpdateAsync(Guid id, SessionUpdateModel model) { if (id.Equals(Guid.Empty)) { throw new ArgumentNullException(nameof(id)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } var found = await Repository.GetByIdAsync(id); if (found == null) { return(null); } Mapper.Map <SessionUpdateModel, Session>(model, found); // verify speaker id and audience id are valid var speaker = await SpeakersRepository.GetByIdAsync(found.SpeakerId); var audience = await AudiencesRepository.GetByIdAsync(found.AudienceId); if (speaker == null || audience == null) { throw new IndexOutOfRangeException(); } found.Speaker = speaker; found.Audience = audience; var updated = await Repository.UpdateAsync(found); await Audit.AuditCreatedAsync($"Session {updated.Title} has been updated"); return(Mapper.Map <SessionDetailsModel>(updated)); }
public Talk(FeedbackService feedbackService, IDataLoaderContextAccessor dataLoaderAccessor, SpeakersRepository speakersRepository) { Field(t => t.Id); Field(t => t.Title); Field(t => t.Description); Field(t => t.SpeakerId); //Field(name: "speaker", type: typeof(Speaker), resolve: context => context.Source.Speaker); ///loads the feedbacks for a talk in one go Field <ListGraphType <FeedbackType> >( "feedbacks", resolve: context => { //his is an example of using a DataLoader to batch requests for loading a collection of items by a key. //This is used when a key may be associated with more than one item. LoadAsync() is called by the field resolver for each User. var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, Conference.Service.Feedback>( "GetReviewsByTalkId", feedbackService.GetAllInOneGo); return(loader.LoadAsync(context.Source.Id)); }); Field <ListGraphType <Speaker> >( "speakers", resolve: context => { var loader = dataLoaderAccessor.Context.GetOrAddCollectionBatchLoader <int, Data.Entities.Speaker>("GetSpeakersForTalk", speakersRepository.GetAllSpeakersInOneGo); return(loader.LoadAsync(context.Source.Id)); }); }
public ConferenceQuery(SpeakersRepository speakersRepo, TalksRepository talksRepo, FeedbackService feedbackService, IDataLoaderContextAccessor accessor) { Field <ListGraphType <Types.Speaker> >( "speakers", Description = "will return all the speakers from current and past editions", resolve: context => speakersRepo.GetAll() ); //Field<ListGraphType<Talk>>( // "talks", // Description = "will return all the talks from current and past editions", // resolve: context => talksRepo.GetAll() //); Field <ListGraphType <Talk>, IEnumerable <Data.Entities.Talk> >() .Name("talks") .Description("Get all talks in the system") .ResolveAsync(ctx => { // Get or add a loader with the key "GetAllUsers" var loader = accessor.Context.GetOrAddLoader("talksdssd", () => talksRepo.GetAllAsync()); // Prepare the load operation // If the result is cached, a completed Task<IEnumerable<User>> will be returned return(loader.LoadAsync()); }); // Field<ListGraphType<FeedbackType>>( // "feedbacks", // Description = "will return all the feedbacks", // resolve: context => feedbackService.GetAll() //); //caches subsequent calls using IDataLoaderContextAccessor Field <ListGraphType <FeedbackType>, IEnumerable <Feedback> >() .Name("feedbacks") .Description("Get all feedbacks") .ResolveAsync(ctx => { // Get or add a loader with the key "GetAllUsers" var loader = accessor.Context.GetOrAddLoader("GetAllFeedbacks", () => feedbackService.GetAll()); // Prepare the load operation // If the result is cached, a completed Task<IEnumerable<User>> will be returned return(loader.LoadAsync()); }); Field <ListGraphType <Types.Talk> >( "talksForASpeaker", Description = "will return all the talks for a speaker", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }), resolve: context => { var id = context.GetArgument <int>("id"); return(talksRepo.GetAllForSpeaker(id)); } ); //gets a speaker by id Field <Speaker>( "speakerById", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id", DefaultValue = 2, Description = "test" }), resolve: context => { var id = context.GetArgument <int>("id"); return(speakersRepo.GetById(id)); } ); //gets a talk by id Field <Talk>( "talk", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "id" }), resolve: context => { var id = context.GetArgument <int>("id"); return(talksRepo.GetById(id)); } ); }
public async Task <IHttpActionResult> Post() { SpeakersRepository speakersRepository = new SpeakersRepository(); var speakerList = speakersRepository.ListSpeakers(); IEnumerable <string> headerValues = this.Request.Headers.GetValues(SUBSCRIPTION_KEY_HEADER); var subscriptionKey = headerValues.FirstOrDefault(); this.httpClient.DefaultRequestHeaders.Accept.Clear(); this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); this.httpClient.DefaultRequestHeaders.Add(SUBSCRIPTION_KEY_HEADER, subscriptionKey); var audio = await this.Request.Content.ReadAsByteArrayAsync(); string enrolledProfiles = string.Join(",", speakerList.Select(x => x.identificationProfileId)); string uri = string.Format(@"https://westus.api.cognitive.microsoft.com/spid/v1.0/identify?identificationProfileIds={0}&shortAudio=true", enrolledProfiles); using (var content = new ByteArrayContent(audio)) { content.Headers.ContentType = new MediaTypeHeaderValue(@"application/json"); var response = await this.httpClient.PostAsync(uri, content); if (!response.IsSuccessStatusCode) { return(InternalServerError(new Exception(await response.Content.ReadAsStringAsync()))); } if (response.Headers.Contains(OPERATION_LOCATION_HEADER)) { string operationLocationURL = response.Headers.GetValues(OPERATION_LOCATION_HEADER).First(); OperationResult operation = new OperationResult { status = OperationStatus.notstarted }; while (operation.status == OperationStatus.notstarted || operation.status == OperationStatus.running) { var operationResult = await GetOperationDetailAsync(operationLocationURL, subscriptionKey); operation = JsonConvert.DeserializeObject <OperationResult>(operationResult); if (operation.status == OperationStatus.succeeded) { if (operation.processingResult.confidence == IdentificationConfidence.Normal || operation.processingResult.confidence == IdentificationConfidence.High) { var identifiedSpeaker = speakerList.Single(x => x.identificationProfileId == operation.processingResult?.identifiedProfileId); return(Ok(new SpeakerResult { id = identifiedSpeaker.identificationProfileId, name = identifiedSpeaker.Name })); } else { return(BadRequest("No se pudo detectar la identidad. Por favor, vuelva a intentarlo.")); } } // TODO: Add error handling. // Wait a bit to try again. Thread.Sleep(300); } } } return(BadRequest()); }