예제 #1
0
 public BookmarkModel(Bookmark bm)
 {
     UserId     = bm.UserId;
     Id         = bm.Id;
     DocumentId = bm.DocumentId;
     if (bm.Document != null)
     {
         Document = new DocModel(bm.Document, false);
     }
     Name     = bm.Name;
     Page     = bm.Page;
     DateTime = bm.DateTime;
 }
예제 #2
0
 public UserModel(User user, bool collections = true)
 {
     if (user == null)
     {
         return;
     }
     Name = user.UserName;
     Info = user.Info;
     // define load avatart url
     if (user.ImageUrl != null)
     {
         ImageUrl = (AvatarStorage + user.ImageUrl);
     }
     Banned = user.Banned;
     Id     = user.Id;
     if (collections)
     {
         Subscribers        = user.Subscribers?.Select(s => new UserModel(s.User, false)).ToList();
         SubscribesToGroups = user.SubscribesToGroups?.Select(gs => new GroupModel(gs.Group, false)).ToList();
         SubscribesToUsers  = user.SubscribesToUsers?.Select(us => us.ToUser != null ? new UserModel(us.ToUser, false) : new UserModel(us.ToUserId)).ToList();
         Documents          = user.Documents?.Where(d => d.DocStatus != Document.DocStatusEnum.Deleted).Select(d => new DocModel(d, false)).ToList();
         Likes         = user.Likes?.Select(l => new DocModel(l.Document, false)).ToList();
         AdminOfGroups = user.AdminOfGroups?.Select(gs => new GroupModel(gs.Group, false)).ToList();
         Participate   = user.Participate?.Select(gs => new GroupModel(gs.Group, false)).ToList();
         Bookmarks     = user.Bookmarks?.Select(bm => new BookmarkModel(bm)).ToList();
     }
     else
     {
         // only ids
         Subscribers        = user.Subscribers?.Select(s => { var um = new UserModel(s.UserId); return(um); }).ToList();
         SubscribesToGroups = user.SubscribesToGroups?.Select(gs => { var gm = new GroupModel(gs.GroupId); return(gm); }).ToList();
         SubscribesToUsers  = user.SubscribesToUsers?.Select(us => { var um = new UserModel(us.ToUserId); return(um); }).ToList();
         Documents          = user.Documents?.Where(d => d.DocStatus == Document.DocStatusEnum.Normal).Select(d => { var dm = new DocModel(d.Id); return(dm); }).ToList();
         Likes         = user.Likes?.Select(l => new DocModel(l.DocumentId)).ToList();
         AdminOfGroups = user.AdminOfGroups?.Select(gs => new GroupModel(gs.GroupId)).ToList();
         Participate   = user.Participate?.Select(gs => new GroupModel(gs.GroupId)).ToList();
         Bookmarks     = user.Bookmarks?.Select(bm => new BookmarkModel()).ToList();
     }
     Rating = user.Rating;
 }