示例#1
0
        // GET: api/Studies
        public IEnumerable <StudyViewModel> GetStudies()
        {
            var studyListViewModel = new List <StudyViewModel>();
            var mapper             = new StudyMapper();

            var studyList = db.GetStudyList();

            foreach (var s in studyList)
            {
                studyListViewModel.Add(mapper.GetStudyViewModel(s));
            }
            return(studyListViewModel);
        }
示例#2
0
        public IHttpActionResult PostStudy(StudyViewModel studyViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            #region SubjectAgeCriteria

            if (studyViewModel.GreaterThanEquals)
            {
                studyViewModel.SubjectMinAgeInequality = "GTOET";
            }
            else if (studyViewModel.GreaterThan)
            {
                studyViewModel.SubjectMinAgeInequality = "GT";
            }

            //Age Min
            var minMonth = (double)studyViewModel.MinMonth / 12;
            studyViewModel.SubjectMinAgeInYears = (double)(studyViewModel.MinYear) + minMonth;

            if (studyViewModel.LessThanEquals)
            {
                studyViewModel.SubjectMaxAgeInequality = "LTOET";
            }
            else if (studyViewModel.LessThan)
            {
                studyViewModel.SubjectMaxAgeInequality = "LT";
            }

            var maxMonth = (double)studyViewModel.MaxMonth / 12;
            studyViewModel.SubjectMaxAgeInYears = (double)(studyViewModel.MaxYear) + maxMonth;

            #endregion

            var studyMapper = new StudyMapper();
            var study       = studyMapper.GetStudy(studyViewModel);

            db.Studies.Add(study);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = study.StudyId }, study));
        }
示例#3
0
        public IHttpActionResult PutStudy(int id, StudyViewModel studyViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != studyViewModel.StudyId)
            {
                return(BadRequest());
            }

            #region SubjectAgeCriteria

            if (studyViewModel.GreaterThanEquals)
            {
                studyViewModel.SubjectMinAgeInequality = "GTOET";
            }
            else if (studyViewModel.GreaterThan)
            {
                studyViewModel.SubjectMinAgeInequality = "GT";
            }

            //Age Min

            var minMonth = (double)studyViewModel.MinMonth / 12;
            studyViewModel.SubjectMinAgeInYears = (double)(studyViewModel.MinYear) + minMonth;

            if (studyViewModel.LessThanEquals)
            {
                studyViewModel.SubjectMaxAgeInequality = "LTOET";
            }
            else if (studyViewModel.LessThan)
            {
                studyViewModel.SubjectMaxAgeInequality = "LT";
            }

            var maxMonth = (double)studyViewModel.MaxMonth / 12;
            studyViewModel.SubjectMaxAgeInYears = (double)(studyViewModel.MaxYear) + maxMonth;

            #endregion
            var studyMapper = new StudyMapper();
            var study       = studyMapper.GetStudy(studyViewModel);

            db.Entry(study).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }