/// <summary> /// Get the Attached Object Unit /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <ListAttachedObjectUnitInput> GetAllAttachedObjectUnit(GetAttachedObjectInputUnit input) { ListAttachedObjectUnitInput lstAttachedObjectInput = new ListAttachedObjectUnitInput(); lstAttachedObjectInput.attachedObjectUnitList = new List <AttachedObjectUnitDto>(); var attachedObjectUnitList = await(from file in _attachedObjectUnitRepository.GetAll() join user in _userUnitRepository.GetAll() on file.CreatorUserId equals user.Id into notes from noteinner in notes.DefaultIfEmpty() where file.TypeOfObjectId == input.TypeOfObjectId && file.ObjectId == input.ObjectId select new { file, noteinner.UserName }).ToListAsync(); foreach (var item in attachedObjectUnitList) { AttachedObjectUnitDto attachedObjectDto = new AttachedObjectUnitDto(); attachedObjectDto.AttachedObjectId = item.file.Id; attachedObjectDto.CreatedUser = item.UserName; attachedObjectDto.CreateDateTime = item.file.CreationTime; Mapper.Map(item.file, attachedObjectDto); //TODO: If you want to return bytes also then uncomment below and also in AttachedObjectUnitDto Byte field. //var binaryObject = await _binaryObjectRepository.GetAsync(item.UserAttachmentFilesId.GetValueOrDefault()); //attachedObjectDto.Bytes = binaryObject.Bytes; lstAttachedObjectInput.attachedObjectUnitList.Add(attachedObjectDto); } return(lstAttachedObjectInput); }
/// <summary> /// GET the File for Download /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <AttachedObjectUnitDto> GetFileAttachedObjecUnit(GetFileAttachedObjectInputUnit input) { var attachedObjectUnit = await _attachedObjectUnitRepository.GetAsync(input.AttachedObjectId); AttachedObjectUnitDto attachedObjectDto = new AttachedObjectUnitDto(); var binaryObject = await _binaryObjectRepository.GetAsync(attachedObjectUnit.UserAttachmentFilesId.GetValueOrDefault()); Mapper.Map(attachedObjectUnit, attachedObjectDto); attachedObjectDto.Bytes = binaryObject.Bytes; return(attachedObjectDto); }