public Result <TModel> Get(int id) { var result = Repository.GetById(id); if (result.IsSuccess) { return(EntityToModel(result.Data)); } return(new ErrorResult <TModel>("Entity with Id " + id + " doesn't exist.")); }
public async Task Execute(MoveTaskCommand command) { // todo: use a custom cosmos stored proc in order to provide a transaction var from = await repo.GetById(command.FromListId); var task = from.Tasks.FirstOrDefault(t => t.Id == command.TaskId); if (task == null) { throw ResourceNotFoundException.FromResourceId(command.TaskId); } var to = await repo.GetById(command.ToListId); from.Tasks.Remove(task); to.Tasks.Add(task); // no transaction so might as well save concurrently await Task.WhenAll(repo.Replace(from), repo.Replace(to)); }
public async Task Execute(DeleteTaskCommand command) { var list = await repo.GetById(command.ListId); var task = list.Tasks.FirstOrDefault(t => t.Id == command.TaskId); if (task == null) { throw ResourceNotFoundException.FromResourceId(command.TaskId); } list.Tasks.Remove(task); await repo.Replace(list); }
public async Task Execute(UpdateTaskCommand command) { var list = await repo.GetById(command.ListId); var task = list.Tasks.FirstOrDefault(t => t.Id == command.TaskId); if (task == null) { throw ResourceNotFoundException.FromResourceId(command.TaskId); } task.Name = command.Name; task.Description = command.Description; await repo.Replace(list); }
public async Task <string> Execute(CreateTaskCommand command) { var list = await repo.GetById(command.ListId); var task = new Domain.Task { Id = Guid.NewGuid().ToString(), Description = command.Description, Name = command.Name }; list.Tasks.Add(task); await repo.Replace(list); return(task.Id); }
public AppQuery( ILabRepository labRepository, IProjectRepository projectRepository, IListRepository listRepository, ISeriesRepository seriesRepository, IPointRepository pointRepository) { #region GetAll Field <ListGraphType <LabType> >( "labs", resolve: context => labRepository.GetAll() ); Field <ListGraphType <ProjectType> >( "projects", resolve: context => projectRepository.GetAll() ); Field <ListGraphType <ListType> >( "lists", resolve: context => listRepository.GetAll() ); Field <ListGraphType <SeriesType> >( "series", resolve: context => seriesRepository.GetAll() ); Field <ListGraphType <PointType> >( "points", resolve: x => pointRepository.GetAll() ); #endregion #region GetById Field <LabType>( "lab", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idLab" }), resolve: context => { return(labRepository.GetById(context.GetArgument <int>("idLab"))); } ); Field <ProjectType>( "project", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idLab" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idProject" } ), resolve: context => { return(projectRepository.GetById( context.GetArgument <int>("idLab"), context.GetArgument <int>("idProject"))); } ); Field <SeriesType>( "serie", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idLab" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idProject" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idSeries" } ), resolve: context => { return(seriesRepository.GetById( context.GetArgument <int>("idLab"), context.GetArgument <int>("idProject"), context.GetArgument <int>("idSeries"))); } ); Field <ListType>( "list", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idLab" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idProject" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idList" } ), resolve: context => { return(listRepository.GetById( context.GetArgument <int>("idLab"), context.GetArgument <int>("idProject"), context.GetArgument <int>("idList"))); } ); Field <PointType>( "point", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idLab" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idProject" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idSeries" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "idPoint" } ), resolve: context => { return(pointRepository.GetById( context.GetArgument <int>("idLab"), context.GetArgument <int>("idProject"), context.GetArgument <int>("idSeries"), context.GetArgument <int>("idPoint"))); } ); #endregion }