/// <summary> /// (数据库内容本地化demo) 更新指定语言版本 /// </summary> /// <param name="id"></param> /// <param name="input"></param> /// <returns></returns> public async Task UpdateAsync(Guid id, ProductDto input) { using (CultureHelper.Use(input.CultureName)) { var entity = await AsyncExecuter.FirstOrDefaultAsync(_ProductRepository.WithDetails(s => s.Entries).Where(s => s.Id == id)); entity.ProductCode = input.ProductCode; if (!entity.Entries.Any()) { entity.Entries.Add(new DemoProductLocalizableEntry { CultureName = input.CultureName, Title = input.Title, Description = input.Description, Name = input.Name }); } else { entity.Entries.First().Title = input.Title; entity.Entries.First().Description = input.Description; entity.Entries.First().Name = input.Name; } } }
public override async Task <CategoryItemDto> GetAsync(Guid id) { var categoryItems = await Repository.GetQueryableAsync(); var query = (from categoryItem in categoryItems join category in _categoryRepository on categoryItem.CategoryId equals category.Id join item in _itemRepository on categoryItem.ItemId equals item.Id where categoryItem.Id == id select new { categoryItem, category, item }); var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (!CurrentTenant.Id.HasValue) { using (_dataFilter.Disable <IMultiTenant>()) { queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); } } if (queryResult == null) { throw new EntityNotFoundException(typeof(CategoryItem), id); } var categoryItDto = ObjectMapper.Map <CategoryItem, CategoryItemDto>(queryResult.categoryItem); categoryItDto.CategoryName = queryResult.category.Name; categoryItDto.ItemName = queryResult.item.Name; return(categoryItDto); }
public async Task <UserDto> Login(LoginDto loginDto) { var password = _stringEncryptionService.Encrypt(loginDto.Password); var user = await AsyncExecuter.FirstOrDefaultAsync(_userRepository.GetAll().Where(t => t.UserName == loginDto.UserName && t.Password == password)); return(ObjectMapper.Map <User, UserDto>(user)); }
public override async Task <WarehouseDto> GetAsync(Guid id) { await CheckGetPolicyAsync(); //Prepare a query to join books and authors var query = from warehouse in Repository join branch in _branchRepository on warehouse.BranchId equals branch.Id where warehouse.Id == id select new { warehouse, branch }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Warehouse), id); } var warehouseDto = ObjectMapper.Map <Warehouse, WarehouseDto>(queryResult.warehouse); warehouseDto.BranchName = queryResult.branch.Name; if (warehouseDto.CreatorId.HasValue) { warehouseDto.CreatorName = _userRepository .FirstOrDefault(user => user.Id == warehouseDto.CreatorId).Name; } if (warehouseDto.LastModifierId.HasValue) { warehouseDto.EditorName = _userRepository .FirstOrDefault(user => user.Id == warehouseDto.CreatorId).Name; } return(warehouseDto); }
public async Task <Event> EventWithDetails(Guid id) { var query = eventRepository .WithDetails(x => x.Attendees) .Where(x => x.Id == id); return(await AsyncExecuter.FirstOrDefaultAsync(query)); }
protected override async Task <UserRole> GetEntityByIdAsync(UserRoleKey id) { // TODO: AbpHelper generated return(await AsyncExecuter.FirstOrDefaultAsync( _repository.Where(e => e.UserId == id.UserId && e.RoleId == id.RoleId ) )); }
public async Task<ProjectBoardDto> GetProjectBoardAsync(Guid id) { var query = _projectRepository .Where(x => x.Id == id) .Select(x => new ProjectBoardDto() { ProjectId = x.Id, Title = x.Title, Description = x.Description }); var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); queryResult.BoardMessageDto = await _boardMessageAppService.GetBoardMessageListByProjectId(id); return queryResult; }
public virtual async Task <ClubDto> GetClubAsync(Guid id) { ClubPlayer clubPlayer = await _clubPlayerRepository.FindAsync(x => x.PlayerId == id && x.IsPrimaryClubOfPlayer); if (clubPlayer == null) { return(null); } IQueryable <Club> clubQueryable = await _clubRepository.GetQueryableAsync(); IQueryable <ClubDto> clubDtoQueryable = ObjectMapper .GetMapper() .ProjectTo <ClubDto>(clubQueryable.Where(x => x.Id == clubPlayer.ClubId)); return(await AsyncExecuter.FirstOrDefaultAsync(clubDtoQueryable)); }
public override async Task <FileDto> GetAsync(Guid id) { var query = from file in Repository join bot in botRepository on file.BotId equals bot.Id where file.Id == id select new { bot, file }; var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(File), id); } var bookDto = ObjectMapper.Map <File, FileDto>(queryResult.file); bookDto.BotName = queryResult.bot.Name; return(bookDto); }
/// <summary> /// 根据书签ID获取书签实体并生成BookMarkDto /// </summary> /// <param name="id"></param> /// <returns></returns> public override async Task <BookMarkDto> GetAsync(Guid id) { var queryable = await Repository.GetQueryableAsync(); var quer = from bookMark in queryable join book in _bookRepository on bookMark.BookId equals book.Id where bookMark.Id == id select new { bookMark, book }; var queryResult = await AsyncExecuter.FirstOrDefaultAsync(quer); if (queryResult == null) { throw new EntityNotFoundException(typeof(BookMark), id); } var bookMarkdto = ObjectMapper.Map <BookMark, BookMarkDto>(queryResult.bookMark); bookMarkdto.BookName = queryResult.book.Name; return(bookMarkdto); }
/// <summary> /// 根据书籍ID获取书籍实体并生成BookDto /// </summary> /// <param name="id"></param> /// <returns></returns> public override async Task <BookDto> GetAsync(Guid id) { /*Repository 作用于TEntity*/ var queryable = await Repository.GetQueryableAsync(); var query = from book in queryable join author in _authorRepository on book.AuthorId equals author.Id where book.Id == id select new { book, author }; var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Book), id); } var bookDto = ObjectMapper.Map <Book, BookDto>(queryResult.book); bookDto.AuthorName = queryResult.author.Name; return(bookDto); }
public async Task <ClassTableDto> GetListByProcessIdAndTsIdAsync(ClassTableQueryByTsIdProcess input) { //Prepare a query to join books and authors var query = from classTable in _classTables join textileProcess in _textileProcesses on classTable.TextileProcessId equals textileProcess.Id where classTable.TsId == input.TsId && classTable.TextileProcessId == input.TextileProcessId select new { classTable, textileProcess }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException("指定的条件没有查到相关的班次记录"); } var classTabLEDto = ObjectMapper.Map <ClassTable, ClassTableDto>(queryResult.classTable); classTabLEDto.ProcessCode = queryResult.textileProcess.ProcessCode; return(classTabLEDto); }
public override async Task <BookDto> GetAsync(Guid id) { //Prepare a query to join books and authors var query = from book in Repository join author in _authorRepository on book.AuthorId equals author.Id where book.Id == id select new { book, author }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Book), id); } var bookDto = ObjectMapper.Map <Book, BookDto>(queryResult.book); bookDto.AuthorName = queryResult.author.Name; return(bookDto); }
public override async Task <BranchDto> GetAsync(Guid id) { await CheckGetPolicyAsync(); var query = from branch in Repository where branch.Id == id select new { branch }; var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Branch), id); } var BranchDto = ObjectMapper.Map <Branch, BranchDto>(queryResult.branch); if (BranchDto.ParentId.HasValue) { var queryParent = from parent in Repository where parent.Id == BranchDto.ParentId select new { parent }; var queryParentResult = await AsyncExecuter.FirstOrDefaultAsync(queryParent); if (queryParentResult != null) { BranchDto.ParentName = queryParentResult.parent.Name; } } if (BranchDto.CreatorId.HasValue) { BranchDto.CreatorName = _userRepository .FirstOrDefault(user => user.Id == BranchDto.CreatorId).Name; } if (BranchDto.LastModifierId.HasValue) { BranchDto.EditorName = _userRepository .FirstOrDefault(user => user.Id == BranchDto.CreatorId).Name; } return(BranchDto); }
public virtual async Task <PlayerProfileDto> GetProfileAsync(Guid id) { IQueryable <Player> playerQueryable = await _playerRepository.GetQueryableAsync(); IQueryable <ClubPlayer> clubPlayerQueryable = await _clubPlayerRepository.GetQueryableAsync(); IQueryable <Club> clubQueryable = await _clubRepository.GetQueryableAsync(); IQueryable <ClubPlayerWithNavigationProperties> clubPlayerWithNavigationPropertiesQueryable = playerQueryable.Where(x => x.Id == id) .SelectMany(x => clubPlayerQueryable.Where(y => y.PlayerId == id && y.IsPrimaryClubOfPlayer).DefaultIfEmpty(), (player, clubPlayer) => new { Player = player, ClubPlayer = clubPlayer }) .SelectMany(x => clubQueryable.Where(y => y.Id == x.ClubPlayer.ClubId).DefaultIfEmpty(), (x, club) => new ClubPlayerWithNavigationProperties() { Player = x.Player, Club = club, }); IQueryable <PlayerProfileDto> playerProfileDtoQueryable = ObjectMapper.GetMapper().ProjectTo <PlayerProfileDto>(clubPlayerWithNavigationPropertiesQueryable); return(await AsyncExecuter.FirstOrDefaultAsync(playerProfileDtoQueryable)); }
public override async Task <ProductDto> GetAsync(Guid id) { await TryGetProductAsync(id); var queryable = await Repository.GetQueryableAsync(); var query = from product in queryable join category in _categoryRepository on product.CategoryId equals category.Id join gig in _gigRepository on product.GigId equals gig.Id where product.Id == id select new { product, category, gig }; var result = await AsyncExecuter.FirstOrDefaultAsync(query); var dto = await MapToGetOutputDtoAsync(result.product); dto.CategoryName = result.category.Name; dto.GigName = result.gig.Title; return(dto); }
//...SERVICE METHODS WILL COME HERE... public async Task <ListingDto> GetAsync(Guid id) { var queryable = await _listingRepository.GetQueryableAsync(); //Prepare a query to join books and authors var query = from listing in queryable join company in _companiesRepository on listing.CompanyId equals company.Id where listing.Id == id select new { listing, company }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Listing), id); } var bookDto = ObjectMapper.Map <Listing, ListingDto>(queryResult.listing); bookDto.CompanyName = queryResult.company.Name; return(bookDto); }
/// <summary> /// 重写GetAsync,获取作者信息,把作者名添加到BookDto中 /// </summary> /// <param name="id"></param> /// <returns></returns> public override async Task <BookDto> GetAsync(Guid id) { await CheckGetPolicyAsync(); return(await _cacheService.GetAsync(BookCacheConsts.CacheKey.Key_Get.FormatWith(id), async() => { //Prepare a query to join books and authors var query = from book in Repository join author in _authorRepository on book.AuthorId equals author.Id where book.Id == id select new { book, author }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Book), id); } var bookDto = ObjectMapper.Map <Book, BookDto>(queryResult.book); bookDto.AuthorName = queryResult.author.Name; return bookDto; })); }
public override async Task <PedidoDto> GetAsync(Guid id) { await CheckGetPolicyAsync(); var query = from pedido in Repository join cliente in _clienteRepository on pedido.ClienteId equals cliente.Id join vendedor in _vendedorRepository on pedido.VendedorId equals vendedor.Id where pedido.Id == id select new { pedido, cliente, vendedor }; var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Pedido), id); } var pedidoDto = ObjectMapper.Map <Pedido, PedidoDto>(queryResult.pedido); pedidoDto.ClienteNombre = queryResult.cliente.Nombre; pedidoDto.VendedorNombre = queryResult.vendedor.Nombre; return(pedidoDto); }
public override async Task <EventDto> GetAsync(int id) { //Get the IQueryable<Book> from the repository var queryable = await Repository.GetQueryableAsync(); //Prepare a query to join books and authors var query = from book in queryable join author in _organizerRepository on book.OrganizerId equals author.Id where book.Id == id select new { book, author }; //Execute the query and get the book with author var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Event), id); } var bookDto = ObjectMapper.Map <Event, EventDto>(queryResult.book); bookDto.OrganizerName = queryResult.author.Name; return(bookDto); }
protected override async Task <District> GetEntityByIdAsync(DistrictKey id) { return(await AsyncExecuter.FirstOrDefaultAsync( (await Repository.GetQueryableAsync()).Where(d => d.CityId == id.CityId && d.Name == id.Name) )); }
private async Task <ItemDto> GetAsyncFromDatabase(Guid id) { var items = await _itemRepository.GetIQueryableItems(); var query = from item in items join unit in _unitRepository on item.UnitId equals unit.Id where item.Id == id select new { Item = item, Unit = unit }; var categoriesItems = await _categoryItemsRepository.GetQueryableAsync(); var query1 = from categoryItem in categoriesItems join category in _categoryRepository on categoryItem.CategoryId equals category.Id join item in _itemRepository on categoryItem.ItemId equals item.Id where categoryItem.ItemId == id select new CategoryItemDto { Id = categoryItem.Id, ItemId = item.Id, ItemName = item.Name, CategoryId = category.Id, CategoryName = category.Name, CreationTime = categoryItem.CreationTime, CreatorId = categoryItem.CreatorId }; var itemDto = new ItemDto(); if (!CurrentTenant.Id.HasValue) { using (_dataFilter.Disable <IMultiTenant>()) { var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Item), id); } itemDto = ObjectMapper.Map <Item, ItemDto>(queryResult.Item); itemDto.UnitName = queryResult.Unit.Name; var queryResult1 = await AsyncExecuter.ToListAsync(query1); itemDto.ItemCategories = queryResult1; } } else { var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query); if (queryResult == null) { throw new EntityNotFoundException(typeof(Item), id); } itemDto = ObjectMapper.Map <Item, ItemDto>(queryResult.Item); itemDto.UnitName = queryResult.Unit.Name; var queryResult1 = await AsyncExecuter.ToListAsync(query1); itemDto.ItemCategories = queryResult1; } return(itemDto); }
protected async override Task <District> GetEntityByIdAsync(DistrictKey id) { return(await AsyncExecuter.FirstOrDefaultAsync(Repository.Where(x => x.CityId == id.CityId && x.Name == id.Name))); }
protected async override Task <Movie> GetEntityByIdAsync(MovieKey id) { var query = Repository.Where(m => m.Id == id.MovieId && m.Name == id.MovieName); return(await AsyncExecuter.FirstOrDefaultAsync(query)); }
public async Task <CmsUser> GetAuthorHasBlogPostAsync(Guid id, CancellationToken cancellationToken = default) { return(await AsyncExecuter.FirstOrDefaultAsync(await CreateAuthorsQueryableAsync(cancellationToken), x => x.Id == id) ?? throw new EntityNotFoundException(typeof(CmsUser), id)); }