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

            ServiceData.Models.Study serviceStudy = new ServiceData.Models.Study
            {
                Id        = given.Id,
                CreatedAt = given.CreatedAt,
                Name      = given.Name,
                Active    = given.Active,
                Code      = given.Code,
                ManagerId = given.ManagerId
            };

            if (given.Manager != null && includeOwner)
            {
                serviceStudy.Manager = User.ToServiceModel(given.Manager);
            }

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

            return(serviceStudy);
        }
Beispiel #2
0
        public static ServiceData.Models.User ToServiceModel(User given)
        {
            ServiceData.Models.User serviceUser = new ServiceData.Models.User
            {
                Id        = given.Id,
                BirthDate = given.BirthDate,
                Name      = given.Name,
                Email     = given.Email,
                Admin     = given.Admin
            };

            if (given.Conditions != null)
            {
                List <ServiceData.Models.UserCondition> conditions = new List <ServiceData.Models.UserCondition>();
                foreach (UserCondition cond in given.Conditions)
                {
                    conditions.Add(UserCondition.ToServiceModel(cond, true));
                }
                serviceUser.Conditions = conditions;
            }

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

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

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

            return(serviceUser);
        }