public PaginatedDto <UserDto> GetUsers(PaginatedRequestCommand cmd) { var users = _membershipService.GetUsers(cmd.Page, cmd.Take); return(users.ToPaginatedDto( users.Select(user => user.ToUserDto()))); }
public PaginatedDto <ShipmentDto> GetShipments(PaginatedRequestCommand cmd) { var shipments = _shipmentService .GetShipments(cmd.Page, cmd.Take); return(shipments.ToPaginatedDto(shipments.Select(sh => sh.ToShipmentDto()))); }
public async Task <PaginatedDto <ShipmentDto> > GetShipmentsAsync(PaginatedRequestCommand paginationCmd) { var parameters = new { key = _affiliateKey, page = paginationCmd.Page, take = paginationCmd.Take }; var responseTask = base.GetAsync(BaseUriTemplate, parameters); var shipments = await HandleResponseAsync(responseTask); return(shipments); }
public PaginatedDto <AffiliateDto> GetAffiliates(PaginatedRequestCommand cmd) { var affiliates = _shipmentService.GetAffiliates( cmd.Page, cmd.Take); return(affiliates.ToPaginatedDto( affiliates.Select(af => af.ToAffiliateDto()))); }
public async Task <PaginatedDto <OrderDto> > GetOrdersAsync(PaginatedRequestCommand paginationCmd) { var parameters = new { key = _clientKey, page = paginationCmd.Page, take = paginationCmd.Take }; var responseTask = base.GetAsync(BaseUriTemplate, parameters); var orders = await HandleResponseAsync(responseTask); return(orders); }
public static SortOptions GenerateSortOptions(PaginatedRequestCommand model) { var sortOptions = new SortOptions { Fields = (model.OrdersBy == null || model.OrdersBy.Length == 0) ? new[] { "Id" } : model.OrdersBy, Directions = (model.Directions == null || model.Directions.Length == 0) ? new[] { "asc" } : model.Directions }; return(sortOptions); }
public async Task <PaginatedDto <ShipmentTypeDto> > GetShipmentTypesAsync(PaginatedRequestCommand paginationCmd) { using (var apiResponse = await base.GetAsync(BaseUriTemplate, paginationCmd)) { if (apiResponse.IsSuccess) { return(apiResponse.Model); } throw new HttpApiRequestException( string.Format(ErrorMessages.HttpRequestErrorFormat, (int)apiResponse.Response.StatusCode, apiResponse.Response.ReasonPhrase), apiResponse.Response.StatusCode, apiResponse.HttpError); } }
public Task <PaginatedDto <TModel> > GetEntitiesAsync(PaginatedRequestCommand request) { var parameters = new { page = request.Page, take = request.Take, type = request.Type, hasDefaultConditions = request.HasDefaultConditions, directions = (request.Directions == null) ? new string[0] : request.Directions, ordersBy = (request.OrdersBy == null) ? new string[0] : request.OrdersBy }; var responseTask = base.GetAsync(BaseUriTemplate, parameters); return(HandleResponseAsync(responseTask).ContinueWith(t => { return t.Result; })); }
public virtual IHttpActionResult Get(PaginatedRequestCommand cmd) { cmd.FilterInternalDictionary = new Dictionary <string, object>(); this.ListSelecting(cmd); var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault(); if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase)) { try { var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null); var paginatedModel = list.ToPaginatedModel <TModel>(null, null); SetViews(paginatedModel.Items); paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray(); paginatedModel.Condition = new Condition(); this.ListSelected(paginatedModel); return(Ok(paginatedModel)); } catch (Exception ex) { return(InternalServerError(ex)); } } try { var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null); var paged = entities.ToPaginatedModel <TModel>(null, null); SetViews(paged.Items); paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray(); paged.Condition = new Condition(); this.ListSelected(paged); return(Ok(paged)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void Delete(int id, int quantidadeEsperada) { BaseResultModel result = null; PaginatedMongoModel <ListaEmpresaMongoModel> listResult = null; "Quando solicitado editar empresa com id {0}" .x(async() => { var user = await service.MongoService.GetMongoObjectByParentId <PessoaMongoModel>(1); if (user == null) { result = new BaseResultModel { IsValid = false, StatusCode = 404, Message = "Profile não encontrado" }; } else { var model = await service.MongoService.GetMongoObjectByParentId <EmpresaClienteMongoModel>(id); result = await service.DeleteEmpresaBindingModel(new DeleteBindingModel { Id = model.Id }); } }); "Então o result deve ser válido e o objeto deve ter sido excluído" .x(() => { Assert.NotNull(result); Assert.Equal(result.IsValid, true); }); "Quando novamente solicitado obter todas as empresas" .x(async() => { var model = new PaginatedRequestCommand { Page = 1, Take = 1000, Type = EnumUtility.GetEnumText(GetTypes.Paged) }; listResult = await service.GetAll <ListaEmpresaMongoModel>(container, model); }); "Então a quantidade de empresas deve ser {1}" .x(() => { Assert.Equal(listResult.Items.Count(), quantidadeEsperada); Reset(true); }); }
public void GetAll(int quantidadeEsperada) { Reset(true); PaginatedMongoModel <ListaEmpresaMongoModel> result = null; "Quando solicitado obter todas as empresas" .x(async() => { var model = new PaginatedRequestCommand { Page = 1, Take = 1000, Type = EnumUtility.GetEnumText(GetTypes.Paged) }; result = await service.GetAll <ListaEmpresaMongoModel>(container, model); }); "Então a quantidade de empresas deve ser {0}" .x(() => { Assert.Equal(result.Items.Count(), quantidadeEsperada); }); }
public void PostInvalid(int tipo, int quantidadeEsperada) { PostResultModel result = null; PaginatedMongoModel <ListaEmpresaMongoModel> listResult = null; "Quando solicitado adicionar empresa com dados inválidos então deve retornar exceção {1}" .x(() => { Assert.ThrowsAsync <AstoveModelInvalidException <Empresa> >(async() => { var user = await service.MongoService.GetMongoObjectByParentId <PessoaMongoModel>(1); if (user == null) { result = new PostResultModel { IsValid = false, StatusCode = 404, Message = "Profile não encontrado" }; } else { var model = await service.GetPostEmpresaBindingModel(new GetPostEmpresaBindingModel { Tipo = tipo }); result = await service.PostEmpresaBindingModel(model, user.CreateInstanceOf <ProfileMongoModel>()); } }); }); "Quando novamente solicitado obter todas as empresas" .x(async() => { var model = new PaginatedRequestCommand { Page = 1, Take = 1000, Type = EnumUtility.GetEnumText(GetTypes.Paged) }; listResult = await service.GetAll <ListaEmpresaMongoModel>(container, model); }); "Então a quantidade de empresas deve ser {6}" .x(() => { Assert.Equal(listResult.Items.Count(), quantidadeEsperada); }); }
// GET /api/cars public PaginatedDto <Car> Get(PaginatedRequestCommand cmd) { return(_carsCtx.GetAll(cmd.Page, cmd.Take).ToPaginatedDto()); }
public virtual IHttpActionResult Get(PaginatedRequestCommand cmd) { cmd.FilterInternalDictionary = new Dictionary <string, object>(); this.ListSelecting(cmd); if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get {0}", cmd.Type)); } var attr = typeof(TModel).GetCustomAttributes(true).OfType <DataEntityAttribute>().FirstOrDefault(); if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.InsertModel), StringComparison.CurrentCultureIgnoreCase)) { try { TRequestModel requestModel = new TRequestModel(); BaseEntity.SetDropDownOptions <TRequestModel, IBindingModel>(requestModel, this.Container); this.ListSelected(requestModel); return(Ok(requestModel)); } catch (Exception ex) { if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType()); } if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)) { ReflectionTypeLoadException typeLoadException = null; if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException) { typeLoadException = ex.InnerException as ReflectionTypeLoadException; } else { typeLoadException = ex as ReflectionTypeLoadException; } var loaderExceptins = typeLoadException.LoaderExceptions; foreach (var tlex in loaderExceptins) { this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source }); } } else { this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException); } //return InternalServerError(base.ErrorMessage(ex)); return(InternalServerError(ex)); } } else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.UpdateModel), StringComparison.CurrentCultureIgnoreCase)) { try { string[] includeProperties = null; if (attr != null) { includeProperties = attr.Include; } TEntity entity = this.Service.GetSingle(cmd.EntityId, includeProperties); if (entity == null) { NotFound(); } //return Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("{0} não encontrado(a)", typeof(TEntity).Name)); TUpdateRequestModel model = entity.ToModel <TUpdateRequestModel, IModel>(this.Container, false, 0); this.ListSelected(model); return(Ok(model)); } catch (Exception ex) { return(InternalServerError(ex)); } } else if (cmd.Type.Equals(AInBox.Astove.Core.Enums.EnumUtility.GetEnumText(GetTypes.PagedGrid), StringComparison.CurrentCultureIgnoreCase)) { if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Info(this.Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, string.Format("Começando Get ", cmd.Type)); } try { var list = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null); var paginatedModel = list.ToPaginatedModel <TModel>(null, null); SetViews(paginatedModel.Items); paginatedModel.Condition = new Condition(); paginatedModel.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray(); this.ListSelected(paginatedModel); return(Ok(paginatedModel)); } catch (Exception ex) { if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), (ex.InnerException == null) ? null : ex.InnerException.GetType()); } if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)) { ReflectionTypeLoadException typeLoadException = null; if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException) { typeLoadException = ex.InnerException as ReflectionTypeLoadException; } else { typeLoadException = ex as ReflectionTypeLoadException; } var loaderExceptins = typeLoadException.LoaderExceptions; foreach (var tlex in loaderExceptins) { this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source }); } } else if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex); } return(InternalServerError(ex)); } } try { var entities = this.Service.GetEntities(this.Container, cmd, typeof(TModel), cmd.OrdersBy, cmd.Directions, (attr != null) ? attr.Include : null); var paged = entities.ToPaginatedModel <TModel>(null, null); SetViews(paged.Items); paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TModel>(ActionEnum.List).ToArray(); paged.Condition = new Condition(); this.ListSelected(paged); return(Ok(paged)); } catch (Exception ex) { if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Info(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, "Tipo da exceção {0} {1}", ex.GetType(), ex.InnerException.GetType()); } if (ex is ReflectionTypeLoadException || (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException)) { ReflectionTypeLoadException typeLoadException = null; if (ex.InnerException != null && ex.InnerException is ReflectionTypeLoadException) { typeLoadException = ex.InnerException as ReflectionTypeLoadException; } else { typeLoadException = ex as ReflectionTypeLoadException; } var loaderExceptins = typeLoadException.LoaderExceptions; foreach (var tlex in loaderExceptins) { this._tracer.Error(Request, string.Format("{0} {1}", this.ControllerContext.ControllerDescriptor.ControllerType.FullName, tlex.GetType().FullName), "Erro: {0} {1}", new[] { tlex.Message, tlex.Source }); } } else if (this.ControllerContext.ControllerDescriptor != null) { this._tracer.Debug(Request, this.ControllerContext.ControllerDescriptor.ControllerType.FullName, ex.InnerException); } return(InternalServerError(ex)); } }
public virtual void ListSelecting(PaginatedRequestCommand command) { }
// GET /carsclient/cars public async Task <PaginatedDto <Car> > Get(PaginatedRequestCommand cmd) { var cars = await _carsClient.GetCars(cmd); return(cars); }
public async static Task <PaginatedMongoModel <TList> > GetAll <TList>(this IEntityService <Empresa> service, IComponentContext container, PaginatedRequestCommand model) where TList : class, IMongoModel, IDto, new() { var result = await service.MongoService.GetMongoListAsync <EmpresaClienteMongoModel, TList>(container, model); var paged = result.ToPaginatedModel <TList>(); paged.ColumnDefinitions = ColumnFactory.GenerateColumnDefinitions <TList>(ActionEnum.List).ToArray(); paged.Condition = new Condition(); return(paged); }
public void Post(int tipo, string nomeFantasia, string cnpj, string cep, int cidadeId, int estadoId, int idOuQuantidadeEsperada) { PostResultModel result = null; PaginatedMongoModel <ListaEmpresaMongoModel> listResult = null; BaseResultModel getResult = null; DropDownStringOptions optionsResult = null; "Quando solicitado adicionar empresa do tipo cliente {1}" .x(async() => { var user = await service.MongoService.GetMongoObjectByParentId <PessoaMongoModel>(1); if (user == null) { result = new PostResultModel { IsValid = false, StatusCode = 404, Message = "Profile não encontrado" }; } else { var model = await service.GetPostEmpresaBindingModel(new GetPostEmpresaBindingModel { Tipo = tipo }); model.CNPJ = cnpj; model.NomeFantasia = nomeFantasia; model.CEP = cep; model.EstadoId = estadoId; model.CidadeId = cidadeId; result = await service.PostEmpresaBindingModel(model, user.CreateInstanceOf <ProfileMongoModel>()); } }); "Então o result deve ser válido e conter as chaves do novo objeto criado com Id {6}" .x(() => { Assert.NotNull(result); Assert.Equal(result.IsValid, true); Assert.Equal(idOuQuantidadeEsperada, int.Parse(result.ParentId)); Assert.NotNull(result.Id); }); "Quando novamente solicitado obter todas as empresas" .x(async() => { var model = new PaginatedRequestCommand { Page = 1, Take = 1000, Type = EnumUtility.GetEnumText(GetTypes.Paged) }; listResult = await service.GetAll <ListaEmpresaMongoModel>(container, model); }); "Então a quantidade de empresas deve ser {6}" .x(() => { Assert.Equal(listResult.Items.Count(), idOuQuantidadeEsperada); }); "Quando for feita uma pesquisa por CNPJ {2}" .x(async() => { getResult = await service.GetEmpresasByDocumentoAsync(new GetEmpresasByDocumento { CNPJ = cnpj }); }); "Então o nome fantasia deve ser {1}" .x(() => { Assert.Equal(getResult.IsValid, true); Assert.IsType <PostOrPutResultModel>(getResult); var empresaResult = (PostOrPutResultModel)getResult; Assert.IsType <PutEmpresaBindingModel>(empresaResult.BindingModel); var binding = (PutEmpresaBindingModel)empresaResult.BindingModel; Assert.Equal(binding.NomeFantasia, nomeFantasia); }); "Quando for feita uma pesquisa por Id {2}" .x(async() => { getResult = await service.GetEmpresaByParentIdAsync(new GetBindingModel { Id = result.ParentId }); }); "Então o nome fantasia deve ser {1}" .x(() => { Assert.Equal(getResult.IsValid, true); Assert.IsType <PostOrPutResultModel>(getResult); var empresaResult = (PostOrPutResultModel)getResult; Assert.IsType <PutEmpresaBindingModel>(empresaResult.BindingModel); var binding = (PutEmpresaBindingModel)empresaResult.BindingModel; Assert.Equal(binding.NomeFantasia, nomeFantasia); }); "Quando for feita uma pesquisa por options por tipo de acesso {0}" .x(async() => { optionsResult = await service.GetEmpresasByTipoAcessoOptions(tipo); }); "Então a lista de opções deve ter {6}-1 itens" .x(() => { Assert.Equal(optionsResult.Items.Count(), idOuQuantidadeEsperada - 1); }); }