示例#1
0
        public ActionResult Create(CohortViewModel cohortVM)
        {
            if (!ModelState.IsValid || cohortVM == null)
            {
                return(View(cohortVM));
            }

            if (!_projectuservalidationservice.UserCanEditProject(cohortVM.MultiPARTProjectID))
            {
                ViewBag.ErrorMessage = "Access Denied. Please contact administrator for further assistance.";
                return(View("Error"));
            }

            Cohort cohort = new Cohort()
            {
                MultiPARTProjectMultiPARTProjectID = cohortVM.MultiPARTProjectID,
                CohortLabel = cohortVM.CohortLabel,

                StrainStrainID = cohortVM.StrainID,
                SampleSize     = cohortVM.SampleSize ?? 0,
                SexID          = cohortVM.SexID,
                MinAge         = cohortVM.MinAge ?? 0,
                MaxAge         = cohortVM.MaxAge ?? 0,
                MinWeight      = cohortVM.MinWeight ?? 0,
                MaxWeight      = cohortVM.MaxWeight ?? 0,
                Details        = cohortVM.Details,

                CreatedBy     = (int)Membership.GetUser().ProviderUserKey,
                LastUpdatedBy = (int)Membership.GetUser().ProviderUserKey
            };

            db.Cohorts.Add(cohort);
            db.SaveChanges();
            return(RedirectToAction("Details", "MultiPARTProject", new { projectid = cohortVM.MultiPARTProjectID }));
        }
        public async Task ThenShouldGetCohortResponse()
        {
            //Arrange
            var Cohort = new Cohort()
            {
                Id = 1, NumberOfDraftApprentices = 1, Apprenticeships = new List <Apprenticeship> {
                    new Apprenticeship {
                        FirstName = "FirstName"
                    }
                }
            };

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetSingleCohortRequest>())).ReturnsAsync(new GetSingleCohortResponse {
                Cohort = Cohort
            });
            var expectedCohort = new CohortViewModel()
            {
                NumberOfDraftApprentices = 1,
                Apprenticeships          = new List <ApprenticeshipViewModel> {
                    new ApprenticeshipViewModel {
                        ApprenticeshipFullName = "FullName"
                    }
                }
            };

            _mockMapper.Setup(m => m.Map <Cohort, CohortViewModel>(Cohort)).Returns(expectedCohort);

            //Act
            var result = await _sut.GetAccount(HashedAccountId, UserId);

            //Assert
            Assert.AreEqual(1, result.Data.CallToActionViewModel.CohortsCount);
        }
示例#3
0
        public IActionResult Index()
        {
            var viewModel = new CohortViewModel();

            viewModel.Cohorts = GetAllCohorts();
            return(View(viewModel));
        }
示例#4
0
        public ActionResult Add()
        {
            CohortViewModel model  = new CohortViewModel();
            var             config = (MtelligentSection)ConfigurationManager.GetSection("Mtelligent");

            model.CohortTypes = config.Cohorts.ToList().Where(a => a.AllowNew).ToList();
            return(View(model));
        }
示例#5
0
        public ActionResult Add(CohortViewModel viewModel)
        {
            var config = (MtelligentSection)ConfigurationManager.GetSection("Mtelligent");

            try
            {
                if (ModelState.IsValid)
                {
                    var cohortType = config.Cohorts[viewModel.SelectedCohortType];

                    Type   t      = Type.GetType(cohortType.TypeName);
                    Cohort cohort = Activator.CreateInstance(t) as Cohort;
                    cohort.Name       = viewModel.Name;
                    cohort.SystemName = viewModel.SystemName;
                    cohort.TypeName   = cohortType.TypeName;

                    foreach (var propInfo in t.GetProperties())
                    {
                        if (Attribute.IsDefined(propInfo, typeof(UserEditableAttribute)))
                        {
                            if (Request["prop-" + propInfo.Name] != null)
                            {
                                if (propInfo.PropertyType == typeof(string))
                                {
                                    propInfo.SetValue(cohort, Request["prop-" + propInfo.Name]);
                                }

                                if (propInfo.PropertyType == typeof(DateTime))
                                {
                                    if (Request["prop-" + propInfo.Name] != string.Empty)
                                    {
                                        propInfo.SetValue(cohort, DateTime.Parse(Request["prop-" + propInfo.Name]));
                                    }
                                }
                            }
                        }
                    }

                    cohort.CreatedBy = HttpContext.User.Identity.Name;
                    cohort           = cohortRepository.Add(cohort);

                    return(Redirect("/Cohorts/"));
                }
                else
                {
                    ViewBag.ErrorMessage = "There is a problem with one of your response.";
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "There is a problem saving the cohort.";
            }

            viewModel.CohortTypes = config.Cohorts.ToList().Where(a => a.AllowNew).ToList();

            return(View(viewModel));
        }
示例#6
0
        public ActionResult Update(int Id)
        {
            CohortViewModel model = new CohortViewModel();

            var cohort = cohortRepository.Get(Id);

            model.Name       = cohort.Name;
            model.SystemName = cohort.SystemName;
            model.Id         = Id;

            var config = (MtelligentSection)ConfigurationManager.GetSection("Mtelligent");

            model.CohortTypes = config.Cohorts.ToList().Where(a => a.AllowNew).ToList();

            var cohortType = config.Cohorts.ToList().Where(a => a.TypeName == cohort.TypeName).FirstOrDefault();

            model.SelectedCohortType = cohortType.Name;

            model.Properties = new List <CustomCohortPropertyInfo>();

            foreach (var propInfo in cohort.GetType().GetProperties())
            {
                if (Attribute.IsDefined(propInfo, typeof(UserEditableAttribute)))
                {
                    var name = propInfo.Name;

                    if (Attribute.IsDefined(propInfo, typeof(DisplayAttribute)))
                    {
                        var attr = (DisplayAttribute[])propInfo.GetCustomAttributes(typeof(DisplayAttribute), false);
                        if (attr.Length > 0)
                        {
                            name = attr[0].Name;
                        }
                    }

                    var required = Attribute.IsDefined(propInfo, typeof(RequiredAttribute));

                    var info = new CustomCohortPropertyInfo()
                    {
                        Name        = propInfo.Name,
                        DisplayName = name,
                        Required    = required,
                        Value       = propInfo.GetValue(cohort).ToString()
                    };

                    model.Properties.Add(info);
                }
            }

            return(View(model));
        }
示例#7
0
        public ActionResult Edit(CohortViewModel cohortVM)
        {
            if (cohortVM == null)
            {
                return(new HttpStatusCodeResult(422));
            }

            if (!ModelState.IsValid)
            {
                ViewBag.StrainList         = new SelectList(db.Strains.Where(p => p.Status == "Current").AsEnumerable(), "StrainID", "StrainName");
                ViewBag.SexList            = new SelectList(db.Options.Where(c => c.Status == "Current" && c.OptionFields.OptionFieldName == "Sex").AsEnumerable(), "OptionID", "OptionValue");
                ViewBag.MultiPARTProjectID = cohortVM.MultiPARTProjectID;

                return(View(cohortVM));
            }

            if (!_projectuservalidationservice.UserCanEditProject(cohortVM.MultiPARTProjectID))
            {
                ViewBag.ErrorMessage = "Access Denied. Please contact administrator for further assistance.";
                return(View("Error"));
            }

            Cohort cohort = new Cohort()
            {
                CohortID = cohortVM.CohortID,
                MultiPARTProjectMultiPARTProjectID = cohortVM.MultiPARTProjectID,
                CohortLabel    = cohortVM.CohortLabel,
                StrainStrainID = cohortVM.StrainID,
                SampleSize     = cohortVM.SampleSize ?? 0,
                SexID          = cohortVM.SexID,
                MinAge         = cohortVM.MinAge ?? 0,
                MaxAge         = cohortVM.MaxAge ?? 0,
                MinWeight      = cohortVM.MinWeight ?? 0,
                MaxWeight      = cohortVM.MaxWeight ?? 0,
                Details        = cohortVM.Details,

                LastUpdatedBy = (int)Membership.GetUser().ProviderUserKey
            };

            db.Entry(cohort).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Details", "MultiPARTProject", new { projectid = cohortVM.MultiPARTProjectID }));
        }
示例#8
0
        //
        // GET: /Cohort/Create

        public ActionResult Create(int projectid = 0)
        {
            if (!_projectuservalidationservice.UserCanEditProject(projectid))
            {
                ViewBag.ErrorMessage = "Access Denied. Please contact administrator for further assistance.";
                return(View("Error"));
            }

            ViewBag.StrainList = new SelectList(db.Strains.Where(p => p.Status == "Current").AsEnumerable(), "StrainID", "StrainName");
            ViewBag.SexList    = new SelectList(db.Options.Where(c => c.Status == "Current" && c.OptionFields.OptionFieldName == "Sex").AsEnumerable(), "OptionID", "OptionValue");

            ViewBag.MultiPARTProjectID = projectid;

            CohortViewModel cohortVM = new CohortViewModel()
            {
                MultiPARTProjectID = projectid
            };

            return(View(cohortVM));
        }
示例#9
0
        //
        // GET: /Cohort/Edit/5

        public ActionResult Edit(int cohortid)
        {
            Cohort cohort = db.Cohorts.Find(cohortid);

            if (cohort == null)
            {
                return(new HttpStatusCodeResult(422));
            }
            if (cohort.Status != "Current")
            {
                return(new HttpStatusCodeResult(422));
            }

            if (!_projectuservalidationservice.UserCanEditProject(cohort.MultiPARTProjectMultiPARTProjectID))
            {
                ViewBag.ErrorMessage = "Access Denied. Please contact administrator for further assistance.";
                return(View("Error"));
            }

            CohortViewModel cohortVM = new CohortViewModel()
            {
                CohortID           = cohort.CohortID,
                MultiPARTProjectID = cohort.MultiPARTProjectMultiPARTProjectID,
                CohortLabel        = cohort.CohortLabel,
                StrainID           = cohort.StrainStrainID,
                SampleSize         = cohort.SampleSize,
                SexID     = cohort.SexID,
                MinAge    = cohort.MinAge,
                MaxAge    = cohort.MaxAge,
                MinWeight = cohort.MinWeight,
                MaxWeight = cohort.MaxWeight,
                Details   = cohort.Details,
            };

            ViewBag.StrainList         = new SelectList(db.Strains.Where(p => p.Status == "Current").AsEnumerable(), "StrainID", "StrainName");
            ViewBag.SexList            = new SelectList(db.Options.Where(c => c.Status == "Current" && c.OptionFields.OptionFieldName == "Sex").AsEnumerable(), "OptionID", "OptionValue");
            ViewBag.MultiPARTProjectID = cohort.MultiPARTProjectMultiPARTProjectID;

            return(View(cohortVM));
        }
示例#10
0
        public ActionResult Update(CohortViewModel viewModel)
        {
            var config = (MtelligentSection)ConfigurationManager.GetSection("Mtelligent");

            try
            {
                if (ModelState.IsValid)
                {
                    var cohortType = config.Cohorts[viewModel.SelectedCohortType];

                    Type   t      = Type.GetType(cohortType.TypeName);
                    Cohort cohort = Activator.CreateInstance(t) as Cohort;
                    cohort.Name       = viewModel.Name;
                    cohort.SystemName = viewModel.SystemName;
                    cohort.TypeName   = cohortType.TypeName;
                    cohort.Id         = viewModel.Id;

                    viewModel.Properties = new List <CustomCohortPropertyInfo>();

                    foreach (var propInfo in t.GetProperties())
                    {
                        if (Attribute.IsDefined(propInfo, typeof(UserEditableAttribute)))
                        {
                            if (Request["prop-" + propInfo.Name] != null)
                            {
                                if (propInfo.PropertyType == typeof(string))
                                {
                                    propInfo.SetValue(cohort, Request["prop-" + propInfo.Name]);
                                }

                                if (propInfo.PropertyType == typeof(DateTime))
                                {
                                    if (Request["prop-" + propInfo.Name] != string.Empty)
                                    {
                                        propInfo.SetValue(cohort, DateTime.Parse(Request["prop-" + propInfo.Name]));
                                    }
                                }
                            }

                            var name = propInfo.Name;

                            if (Attribute.IsDefined(propInfo, typeof(DisplayAttribute)))
                            {
                                var attr = (DisplayAttribute[])propInfo.GetCustomAttributes(typeof(DisplayAttribute), false);
                                if (attr.Length > 0)
                                {
                                    name = attr[0].Name;
                                }
                            }

                            var required = Attribute.IsDefined(propInfo, typeof(RequiredAttribute));

                            viewModel.Properties.Add(new CustomCohortPropertyInfo()
                            {
                                Name        = propInfo.Name,
                                DisplayName = name,
                                Required    = required,
                                Value       = Request["prop-" + propInfo.Name]
                            });
                        }
                    }

                    cohort.UpdatedBy = HttpContext.User.Identity.Name;
                    cohort           = cohortRepository.Update(cohort);

                    return(Redirect("/Cohorts/"));
                }
                else
                {
                    ViewBag.ErrorMessage = "There is a problem with one of your response.";
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "There is a problem saving the cohort.";
            }

            viewModel.CohortTypes = config.Cohorts.ToList().Where(a => a.AllowNew).ToList();

            return(View(viewModel));
        }