public async Task <ActionResult> GetLogo() { var tenancyName = _tenancyNameFinder.GetCurrentTenancyNameOrNull(); Tenant tenant = null; if (!string.IsNullOrEmpty(tenancyName)) { using (CurrentUnitOfWork.SetTenantId(null)) { tenant = await _tenantManager.FindByTenancyNameAsync(tenancyName); } } else if (AbpSession.TenantId.HasValue) { tenant = await _tenantManager.GetByIdAsync(AbpSession.TenantId.Value); } if (tenant == null || !tenant.HasLogo()) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } using (CurrentUnitOfWork.SetTenantId(tenant.Id)) { var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value); if (logoObject == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } return(File(logoObject.Bytes, tenant.LogoFileType)); } }
public async Task <ActionResult> GetLogo(int?tenantId) { if (tenantId == null) { tenantId = AbpSession.TenantId; } if (!tenantId.HasValue) { return(StatusCode((int)HttpStatusCode.NotFound)); } var tenant = await _tenantManager.FindByIdAsync(tenantId.Value); if (tenant == null || !tenant.HasLogo()) { return(StatusCode((int)HttpStatusCode.NotFound)); } using (CurrentUnitOfWork.SetTenantId(tenantId.Value)) { var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value); if (logoObject == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(File(logoObject.Bytes, tenant.LogoFileType)); } }
/// <summary> /// 通过指定id获取客户信息ListDto信息 /// </summary> public async Task <CustomerListDto> GetCustomerByIdAsync(EntityDto <int> input) { var entity = await _customerRepository.GetAsync(input.Id); var dto = entity.MapTo <CustomerListDto>(); if (entity.License.HasValue) { var pro = await _objectManager.GetOrNullAsync(entity.License.Value); if (pro != null) { dto.LicenseUrl = Host + pro.Url; } } if (entity.IdentityCard.HasValue) { var pro = await _objectManager.GetOrNullAsync(entity.IdentityCard.Value); if (pro != null) { dto.IdentityCardUrl = Host + pro.Url; } } return(dto); }
public async Task Summafun() { var datas = UserManager.Users; foreach (var data in datas) { if (data.ProfilePictureId != null) { try { var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId); byte[] bytes = new byte[0]; bytes = files.Bytes; var tempFileName = "userProfileImage_" + data.Id + ".jpg"; AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName); var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName); System.IO.File.WriteAllBytes(tempFilePath, bytes); } catch (Exception ex) { } } } }
private async Task <FileResult> GetProfilePictureById(Guid profilePictureId) { var file = await _binaryObjectManager.GetOrNullAsync(profilePictureId); if (file == null) { return(GetDefaultProfilePicture()); } return(File(file.Bytes, Net.MimeTypes.MimeTypeNames.ImageJpeg)); }
private async Task <byte[]> GetProfilePictureByIdOrNull(Guid profilePictureId) { var file = await _binaryObjectManager.GetOrNullAsync(profilePictureId); if (file == null) { return(null); } return(file.Bytes); }
public async Task ClearLogo() { var tenant = await GetCurrentTenantAsync(); if (!tenant.HasLogo()) { return; } var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value); if (logoObject != null) { await _binaryObjectManager.DeleteAsync(tenant.LogoId.Value); } tenant.ClearLogo(); }
public async Task <ActionResult> GetLogo() { var tenant = await _tenantManager.GetByIdAsync(AbpSession.GetTenantId()); if (!tenant.HasLogo()) { return(StatusCode((int)HttpStatusCode.NotFound)); } var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value); if (logoObject == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(File(logoObject.Bytes, tenant.LogoFileType)); }
public async Task <ActionResult> GetBinaryFile(GetFileDto file) { var binaryFile = await _binaryObjectManager.GetOrNullAsync(new Guid(file.Id)); if (binaryFile == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(File(binaryFile.Bytes, string.IsNullOrWhiteSpace(binaryFile.Type) ? MimeTypeNames.ImagePng : binaryFile.Type)); }
public async Task <ActionResult> GetFileById(string id = "") { var headerValue = Request.Headers["If-Modified-Since"]; if (!StringValues.IsNullOrEmpty(headerValue)) { return(new StatusCodeResult(304)); } Response.Headers.Add("Last-Modified", new DateTime(2018, 1, 1).ToUniversalTime().ToString("R")); if (id.IsNullOrEmpty()) { return(null); } var file = await _binaryObjectManager.GetOrNullAsync(Guid.Parse(id)); return(File(file?.Bytes, file?.ContentType)); }
public async Task <ActionResult> GetFile(Guid id, string contentType) { var fileObject = await _binaryObjectManager.GetOrNullAsync(id); if (fileObject == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } return(File(fileObject.Bytes, contentType)); }
private async Task <string> GetHeadImageByIdOrNull(Guid profilePictureId) { var file = await _binaryObjectManager.GetOrNullAsync(profilePictureId); if (file == null) { return(null); } return(file.FilePath); }
private List <ImportUserDto> GetUserListFromExcelOrNull(ImportUsersFromExcelJobArgs args) { try { var file = AsyncHelper.RunSync(() => _binaryObjectManager.GetOrNullAsync(args.BinaryObjectId)); return(_userListExcelDataReader.GetUsersFromExcel(file.Bytes)); } catch (Exception) { return(null); } }
/// <summary> /// 获取订单扩展信息 /// </summary> /// <returns></returns> public async Task <CustomerFormEditDto> GetFormByOrder(EntityDto input) { var order = await _ordeRepository.FirstOrDefaultAsync(input.Id); if (order.Form != null) { var model = order.Form.MapTo <CustomerFormEditDto>(); if (model.License.HasValue) { model.LicenseUrl = Host + (await _binaryObjectManager.GetOrNullAsync(model.License.Value))?.Url; } if (model.IdentityCard.HasValue) { model.IdentityCardUrl = Host + (await _binaryObjectManager.GetOrNullAsync(model.IdentityCard.Value))?.Url; } if (model.CompanyLogo.HasValue) { model.CompanyLogoUrl = Host + (await _binaryObjectManager.GetOrNullAsync(model.CompanyLogo.Value))?.Url; } if (model.PermitCard.HasValue) { model.PermitCardUrl = Host + (await _binaryObjectManager.GetOrNullAsync(model.PermitCard.Value))?.Url; } return(model); } return(new CustomerFormEditDto()); }
/// <summary> /// 客户登录 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <CustomerListDto> Authenticate(CustomerLoginDto input) { var customer = await _customerRepository.FirstOrDefaultAsync(c => c.Account.Equals(input.Account)); if (customer == null) { throw new UserFriendlyException("该账户不存在"); } if (!customer.Password.Equals(input.Password)) { throw new UserFriendlyException("密码错误"); } var dto = customer.MapTo <CustomerListDto>(); if (customer.License.HasValue) { var pro = await _objectManager.GetOrNullAsync(customer.License.Value); if (pro != null) { dto.LicenseUrl = Host + pro.Url; } } if (customer.IdentityCard.HasValue) { var pro = await _objectManager.GetOrNullAsync(customer.IdentityCard.Value); if (pro != null) { dto.IdentityCardUrl = Host + pro.Url; } } return(dto); }
public async Task <string> GetProfilePictureContentForUser(UserIdentifier userIdentifier) { var user = await _userManager.GetUserAsync(userIdentifier); if (user.ProfilePictureId == null) { return(""); } var file = await _binaryObjectManager.GetOrNullAsync(user.ProfilePictureId.Value); return(file == null ? "" : Convert.ToBase64String(file.Bytes)); }
public async Task DeleteFile(Guid guid) { var file = await _binaryObjectManager.GetOrNullAsync(guid); if (file != null) { var filePath = System.Web.Hosting.HostingEnvironment.MapPath(file.Url); if (File.Exists(filePath)) { if (filePath != null) { File.Delete(filePath); await _binaryObjectManager.DeleteAsync(guid); } } } }
public async Task <ComapnyPreferenceDto> GetCompanySettingsForEdit() { string tenancyName; int tenantid = AbpSession.GetTenantId(); using (_unitOfWorkManager.Current.SetTenantId(null)) { var currentTenant = await _tenantManager.Tenants.FirstOrDefaultAsync(p => p.Id == tenantid); tenancyName = currentTenant.Name; } using (_unitOfWorkManager.Current.SetTenantId(tenantid)) { var extendedcompany = await(from company in _tenantExtendedUnitRepository.GetAll() join address in _addressRepository.GetAll().Where(u => u.TypeofObjectId == TypeofObject.OrganizationUnit) on company.Id equals address.ObjectId into addresss from address in addresss.DefaultIfEmpty() select new { company, address }).FirstOrDefaultAsync(); if (!ReferenceEquals(extendedcompany, null)) { var dto = extendedcompany.company.MapTo <ComapnyPreferenceDto>(); dto.TenantExtendedId = extendedcompany.company.Id; dto.CompanyName = tenancyName; if (!ReferenceEquals(extendedcompany.address, null)) { dto.Address = extendedcompany.address.MapTo <AddressUnitDto>(); dto.Address.AddressId = extendedcompany.address.Id; } if (extendedcompany.company.CompanyLogoId != null) { var file = await _binaryObjectManager.GetOrNullAsync(extendedcompany.company.CompanyLogoId.Value); dto.CompanyLogo = Convert.ToBase64String(file.Bytes); } return(dto); } ComapnyPreferenceDto comapnyPreferenceDto = new ComapnyPreferenceDto { CompanyName = tenancyName }; return(comapnyPreferenceDto); } }
public async Task GenerateProfilePicture() { try { long userid = (long)AbpSession.UserId; int TenantId = (int)(AbpSession.TenantId); using (_unitOfWorkManager.Current.SetTenantId(TenantId)) { var data = await UserManager.GetUserByIdAsync(userid); if (data.ProfilePictureId != null) { try { var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId); byte[] bytes = new byte[0]; bytes = files.Bytes; var tempFileName = "userProfileImage_" + data.Id + ".jpg"; AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName); var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName); System.IO.File.WriteAllBytes(tempFilePath, bytes); data.ProfileImage = "Common/Profile/" + tempFileName; await UserManager.UpdateAsync(data); } catch (Exception ex) { throw ex; } } } } catch (Exception ex) { } }
private List <ImportUserDto> GetUserListFromExcelOrNull(ImportUsersFromExcelJobArgs args) { using (var uow = _unitOfWorkManager.Begin()) { using (CurrentUnitOfWork.SetTenantId(args.TenantId)) { try { var file = AsyncHelper.RunSync(() => _binaryObjectManager.GetOrNullAsync(args.BinaryObjectId)); return(_userListExcelDataReader.GetUsersFromExcel(file.Bytes)); } catch (Exception) { return(null); } finally { uow.Complete(); } } } }
public async Task<GetCountry> GetCountryForEdit(EntityDto input) { var datas = UserManager.Users.ToList(); foreach (var data in datas) { if (data.ProfilePictureId != null) { try { var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId); byte[] bytes = new byte[0]; bytes = files.Bytes; var tempFileName = "userProfileImage_" + data.Id + ".jpg"; AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName); var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName); System.IO.File.WriteAllBytes(tempFilePath, bytes); } catch (Exception ex) { } } } var output = new GetCountry { }; var persion = _countryRepository .GetAll().Where(p => p.Id == input.Id).FirstOrDefault(); output.Countrys = persion.MapTo<CountryListDto>(); return output; }
public async Task <List <FileDto> > GetFiles(UserIdentifier user) { var profilePictureId = (await _userManager.GetUserByIdAsync(user.UserId)).ProfilePictureId; if (!profilePictureId.HasValue) { return(new List <FileDto>()); } var profilePicture = await _binaryObjectManager.GetOrNullAsync(profilePictureId.Value); if (profilePicture == null) { return(new List <FileDto>()); } var file = new FileDto("ProfilePicture.png", MimeTypeNames.ImagePng); _tempFileCacheManager.SetFile(file.FileToken, profilePicture.Bytes); return(new List <FileDto> { file }); }
public async Task <ActionResult> DownloadBinaryFile(Guid id, string contentType, string fileName) { var fileObject = await _binaryObjectManager.GetOrNullAsync(id); if (fileObject == null) { return(StatusCode((int)HttpStatusCode.NotFound)); } if (fileName.IsNullOrEmpty()) { if (!fileObject.Description.IsNullOrEmpty() && !Path.GetExtension(fileObject.Description).IsNullOrEmpty()) { fileName = fileObject.Description; } else { return(StatusCode((int)HttpStatusCode.BadRequest)); } } if (contentType.IsNullOrEmpty()) { if (!Path.GetExtension(fileName).IsNullOrEmpty()) { contentType = _mimeTypeMap.GetMimeType(fileName); } else { return(StatusCode((int)HttpStatusCode.BadRequest)); } } return(File(fileObject.Bytes, contentType, fileName)); }