Beispiel #1
0
        public static Study ToAppModel(ServiceData.Models.Study given, bool includeOwner)
        {
            if (given == null)
            {
                return(null);
            }

            Study appStudy = new Study
            {
                Id        = given.Id,
                CreatedAt = given.CreatedAt,
                Name      = given.Name,
                Active    = given.Active,
                Code      = given.Code,
                ManagerId = given.ManagerId
            };

            if (given.Manager != null && includeOwner)
            {
                appStudy.Manager = User.ToAppModel(given.Manager);
            }

            if (given.StudyEnrolments != null)
            {
                appStudy.StudyEnrolments = new List <StudyEnrolment>();
                foreach (ServiceData.Models.StudyEnrolment se in given.StudyEnrolments)
                {
                    appStudy.StudyEnrolments.Add(StudyEnrolment.ToAppModel(se, false, true));
                }
            }

            return(appStudy);
        }
Beispiel #2
0
        public static User ToAppModel(ServiceData.Models.User given)
        {
            if (given == null)
            {
                return(null);
            }

            User appUser = new User
            {
                Id         = given.Id,
                BirthDate  = given.BirthDate,
                Name       = given.Name,
                Conditions = new List <UserCondition>(),
                Email      = given.Email,
                Admin      = given.Admin
            };

            if (given.Conditions != null)
            {
                foreach (ServiceData.Models.UserCondition cond in given.Conditions.ToList())
                {
                    appUser.Conditions.Add(UserCondition.ToAppModel(cond, true));
                }
            }

            if (given.Shares != null)
            {
                List <Share> shares = new List <Share>();
                foreach (ServiceData.Models.Share sh in given.Shares)
                {
                    shares.Add(Share.ToAppModel(sh, false));
                }
                appUser.Shares = shares;
            }

            if (given.ManagedStudies != null)
            {
                List <Study> studies = new List <Study>();
                foreach (ServiceData.Models.Study st in given.ManagedStudies)
                {
                    studies.Add(Study.ToAppModel(st, false));
                }
                appUser.ManagedStudies = studies;
            }

            if (given.StudyEnrolments != null)
            {
                List <StudyEnrolment> enrolled = new List <StudyEnrolment>();
                foreach (ServiceData.Models.StudyEnrolment st in given.StudyEnrolments)
                {
                    enrolled.Add(StudyEnrolment.ToAppModel(st, true, false));
                }
                appUser.StudyEnrolments = enrolled;
            }

            return(appUser);
        }