本文整理汇总了C#中ServiceClient.GetRight方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceClient.GetRight方法的具体用法?C# ServiceClient.GetRight怎么用?C# ServiceClient.GetRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceClient
的用法示例。
在下文中一共展示了ServiceClient.GetRight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRight
/* TODO - It is noted that it should never be called by other than the controller.
* Do we even need a public method then?
* If it should only be used by the controller, it can just use client.GetRight(...) as it already does.
*
/// <summary>Looks up a Right by the email of the User and the Id of the Item involved.</summary>
/// <param name="email">The Email of the User whom the Right concerns.</param>
/// <param name="itemId">The Id of the Item which the Right concerns.</param>
/// <returns>The Right with the matching email and itemId.</returns>
private static Right GetRight(string email, int itemId)
{
throw new NotImplementedException();
}
*/
/// <summary>Updates the exising right that has matching UserEmail and ItemId fields, with the rest of the fields from the given updatedRight.</summary>
/// <param name="updatedRight">The updated Right object.</param>
public static void UpdateRight(Right updatedRight)
{
if (_sessionUser == null)
throw new NotLoggedInException();
if (updatedRight == null || updatedRight.UserEmail == null)
throw new InadequateObjectException();
using (var client = new ServiceClient())
{
Right right;
try
{
right = client.GetRight(updatedRight.UserEmail, updatedRight.ItemId);
}
catch (Exception)
{
throw new OriginalNotFoundException();
}
if(right == null)
throw new OriginalNotFoundException();
Item item = null;
if (FileExists(updatedRight.ItemId))
item = client.GetFileInfoById(updatedRight.ItemId);
if (PackageExists(updatedRight.ItemId))
item = client.GetPackageById(updatedRight.ItemId);
if(item == null)
throw new ObjectNotFoundException();
if (_sessionUser.Type != UserType.admin
&& !_sessionUser.Email.Equals(item.OwnerEmail)
&& !HasEditRights(updatedRight.ItemId))
throw new InsufficientRightsException();
client.UpdateRight(updatedRight);
}
}
示例2: HasViewRights
/// <summary>
/// Utility method that checks whether the current user has
/// viewing rights to the Item which is identified by the given itemId.
/// NOTE - This only checks if there exists a Right object stating that
/// the current user has view/edit rights. It does NOT check if the user
/// is the owner of the Item, which would also permit viewing.
/// </summary>
/// <param name="itemId">The id of the Item in question.</param>
/// <returns>True of the current user can view the item, false if not.</returns>
public static bool HasViewRights(int itemId)
{
using (var client = new ServiceClient())
{
var right = client.GetRight(_sessionUser.Email, itemId);
// NOTE - We're using the current systems datetime.
// Users can thus regain rights that have run out, by changing their clocks.
return right != null && (right.Until == null || DateTime.Compare(right.Until.Value, DateTime.Now) > 0);
}
}