コード例 #1
0
 public static User GetById(int id, UserRelatedData relatedData = UserRelatedData.None)
 {
     using (IUnitOfWork unitOfWork = new cmiUnitOfWork())
     {
         Repository <User> repository = new Repository <User>(unitOfWork);
         return(repository.Get(u => u.ID == id, null, GetIncludeProperties(relatedData)).SingleOrDefault()); // && u.IsApproved
     }
 }
コード例 #2
0
        public static ProfileItem GetProfileByUserId(int id, int eventNumber, UserRelatedData relatedData = UserRelatedData.None)
        {
            using (IUnitOfWork unitOfWork = new cmiUnitOfWork())
            {
                Repository <User> repositoryUser = new Repository <User>(unitOfWork);
                User outUser = repositoryUser.Get(u => u.ID == id, null, GetIncludeProperties(relatedData)).SingleOrDefault();

                Repository <GroupInvite> repositoryGroupInvite = new Repository <GroupInvite>(unitOfWork);
                List <GroupInvite>       outGroupInvite        = repositoryGroupInvite.Get(gi => gi.UserMail == outUser.UserName, "Group").ToList();

                Repository <UsersToEvent> repositoryUsersToEvent = new Repository <UsersToEvent>(unitOfWork);
                List <UsersToEvent>       outUsersToEvent        = repositoryUsersToEvent.Get(ue => ue.UserID == id && ue.Event.StartTime >= DateTime.Today, "Event").Take(eventNumber).ToList();

                return(new ProfileItem {
                    user = outUser, groupInvite = outGroupInvite, usersToEvent = outUsersToEvent
                });
            }
        }
コード例 #3
0
        private static string GetIncludeProperties(UserRelatedData includes)
        {
            string includeProperties = "";

            switch (includes)
            {
            case UserRelatedData.None:
                break;

            case UserRelatedData.Type:
                includeProperties = @"UserType";
                break;

            case UserRelatedData.Events:
                includeProperties = @"UsersToEvents";
                break;

            case UserRelatedData.Groups:
                includeProperties = @"UsersToGroups.Group";
                break;

            case UserRelatedData.GroupsEvents:
                includeProperties = @"Groups,Events";
                break;

            case UserRelatedData.UsersToEventsGroups:
                includeProperties = @"UsersToEvents.Event,UsersToGroups.Group";
                break;

            case UserRelatedData.All:
                //includeProperties = @"UsersToEvents,UsersToGroups,UserType,Events,Events.UsersToEvents,Groups,Groups.GroupInvites,Groups.UsersToGroups";
                includeProperties = @"Events.UsersToEvents,Groups.GroupInvites,Groups.Events.UsersToEvents,Groups.UsersToGroups,UsersToEvents,UsersToGroups";
                break;



            default:
                break;
            }

            return(includeProperties);
        }