public static StudyEnrolment ToAppModel(ServiceData.Models.StudyEnrolment given, bool includeStudy, bool includeUser) { if (given == null) { return(null); } StudyEnrolment appEnrolment = new StudyEnrolment { Id = given.Id, CreatedAt = given.CreatedAt, StudyId = given.StudyId, UserId = given.UserId, Enrolled = given.Enrolled }; if (given.Study != null && includeStudy) { appEnrolment.Study = Study.ToAppModel(given.Study, true); } if (given.User != null && includeUser) { appEnrolment.User = User.ToAppModel(given.User); } return(appEnrolment); }
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); }
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); }
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); }