private async Task SetRandomProfilePictureAsync(User user) { try { //Save a random profile picture var storedFile = new TenantCompanyLogo(user.TenantId, GetRandomProfilePictureBytes()); await _binaryObjectManager.SaveAsync(storedFile); //Update new picture on the user user.ProfilePictureId = storedFile.Id; await CurrentUnitOfWork.SaveChangesAsync(); } catch { //we can ignore this exception } }
public async Task <JsonResult> UploadLogo() { try { if (Request.Files.Count <= 0 || Request.Files[0] == null) { throw new UserFriendlyException(L("File_Empty_Error")); } var file = Request.Files[0]; if (file.ContentLength > 30720) //30KB { throw new UserFriendlyException(L("File_SizeLimit_Error")); } var fileBytes = file.InputStream.GetAllBytes(); if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif)) { throw new UserFriendlyException("File_Invalid_Type_Error"); } var logoObject = new TenantCompanyLogo(AbpSession.GetTenantId(), fileBytes); await _binaryObjectManager.SaveAsync(logoObject); var tenant = await _tenantManager.GetByIdAsync(AbpSession.GetTenantId()); tenant.LogoId = logoObject.Id; tenant.LogoFileType = file.ContentType; return(Json(new AjaxResponse(new { id = logoObject.Id, fileType = tenant.LogoFileType }))); } catch (UserFriendlyException ex) { return(Json(new AjaxResponse(new ErrorInfo(ex.Message)))); } }