Click or drag to resize

IUserResource Interface

Manage a user resource.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public interface IUserResource

The IUserResource type exposes the following members.

Properties
  NameDescription
Public propertyFileName
Indicates the name of the resource file.
Public propertyFormat
Indicates the format of the resource (ex: image/URL)
Public propertyId
Identifier of the user resource
Public propertyIsModified
Flag to indicates if the object has been modified since his initialization.
Public propertyUserId
Identifier of the user associated with that resource
Public propertyValue
Get the resource.
Top
Methods
  NameDescription
Public methodReload
Reload the resource using the current database value.
Public methodSave
Save the modification in the database if the object has been modified.
Public methodCode exampleSetImage
Set the value of the resource as an image.
Public methodCode exampleSetUrl
Set the value of the resource as an URL.
Top
Examples

Set the user avatar

var httpRequest = HttpContext.Current.Request;  
if (httpRequest.Files.Count != 1)  
{
   throw new Exception("No image or too many image found in the request. The request accept exactly 1 image file.");
}
var imageFile = httpRequest.Files[0];
var binaryReader = new BinaryReader(imageFile.InputStream);
var bytes = b.ReadBytes(imageFile.ContentLength); 
var context = ContextFactory.CreateByLoginOrEmailAndPassword("login", "secret");
var user = context.User;
var resource = user.Avatar;
var result = resource.SetImage(imageFile.FileName, bytes);
if (!result.Success)
{
    throw result.Exception;
}
See Also