示例#1
0
 public static bool IsOwner(this HtmlHelper helper, IOwnableDO ownableDO)
 {
     bool isOwner = false;
     IPrincipal userPrincipal = helper.ViewContext.HttpContext.User;
     if (userPrincipal.Identity.IsAuthenticated)
     {
         IListenToUser user = (IListenToUser)helper.ViewContext.HttpContext.User;
         isOwner = user.UserId == ownableDO.OwnerID;
     }
     return isOwner;
 }
示例#2
0
        public static IOwnableDO SetOwner(IOwnableDO ownableDO, IPrincipal user)
        {
            if (user.Identity.IsAuthenticated)
            {
                ownableDO.OwnerID = ((ListenToUser)user).UserId;
            }
            else
            {
                throw new Exception("Cannot set owner, user is not authenticated");
            }

            return ownableDO;
        }