public async Task <CharityInfoItemResponseDto> GetCharityInfoItem(Expression <Func <CharitableInformationItem, bool> > predicate) { List <CharitableInformationItem> lstCharitiesInfoItem = null; var query = CharitableItemRepository.GetWhereAsQueryable(predicate).Include(p => p.Item).ThenInclude(p => p.Group); lstCharitiesInfoItem = await query.ToListAsync(); if (lstCharitiesInfoItem == null || lstCharitiesInfoItem.Count == 0) { return(new CharityInfoItemResponseDto() { items = new List <ItemResponseDto>() }); } var lstItems = lstCharitiesInfoItem.Select(e => e.Item).Where(i => i.IsActive.Equals(true)).ToList(); var lstCharityInfoItemDto = Mapper.Map <IEnumerable <ItemResponseDto> >(lstItems); var lstItemsDto = new CharityInfoItemResponseDto(); lstItemsDto.items = lstCharityInfoItemDto.ToList(); return(lstItemsDto); }
public async Task UpdateCharityInfoItem(Guid charitableEntityId, CharityInfoItemDto charityInfoDto) { var charityInfo = Repository.GetWhereAsQueryable(c => c.CharitableEntityId == charitableEntityId).First(); if (charityInfoDto.items != null) { // Removing all current charities / items var charityItems = await CharitableItemRepository.GetWhereAsync(p => p.CharitableInformationId == charityInfo.Id); if (charityItems != null) { CharitableItemRepository.DeleteRange(charityItems); } foreach (var item in charityInfoDto.items) { await CharitableItemRepository.AddAsync(new CharitableInformationItem() { CharitableInformationId = charityInfo.Id, ItemId = item }); } } await this.Repository.SaveAsync(); }