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; }
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; }