public static GenotypingViewModel Create(IRepositoryFactory repositoryFactory, User user, JobType jobType = null, GenotypingPostModel postModel = null) { var viewModel = new GenotypingViewModel() { JobType = jobType, JobTypes = jobType == null ? repositoryFactory.JobTypeRepository.Queryable.Where(a => a.Genotyping).ToList() : new List<JobType>(), PostModel = postModel ?? new GenotypingPostModel() {NumPlates = 1} }; if (jobType != null) { var rid = postModel != null && postModel.RechargeAccount != null ? postModel.RechargeAccount.Id : -1; viewModel.RechargeAccounts = new SelectList(user.RechargeAccounts, "Id", "AccountNum", rid); var pts = new List<SelectListItem>(); pts.Add(new SelectListItem() { Value = ((int)Core.Resources.PlateTypes.NinetySix).ToString(), Text = EnumUtility.GetEnumDescription(Core.Resources.PlateTypes.NinetySix) }); pts.Add(new SelectListItem() { Value = ((int)Core.Resources.PlateTypes.ThreeEightyFour).ToString(), Text = EnumUtility.GetEnumDescription(Core.Resources.PlateTypes.ThreeEightyFour) }); viewModel.PlateTypes = new SelectList(pts, "Value", "Text"); var did = postModel != null && postModel.Dyes != null ? postModel.Dyes : new List<int>(); viewModel.Dyes = new MultiSelectList(repositoryFactory.DyeRepository.Queryable.Where(a => a.Genotyping), "Id", "Name", did); } return viewModel; }
private void ValidateGenotyping(GenotypingPostModel postModel) { if (postModel.NumPlates <= 0) { ModelState.AddModelError("PostModel.NumPlates", "More than one plate is required."); } if (postModel.PlateNames != null && postModel.PlateNames.Count(a => !string.IsNullOrEmpty(a)) < postModel.NumPlates) { ModelState.AddModelError("PostModel.PlateNames", "Please specify a name for each plate."); } if (postModel.Dyes.Count <= 0) { ModelState.AddModelError("PostModel.Dyes", "At least one dye must be specified."); } }
public ActionResult Create(int?id, GenotypingPostModel postModel) { JobType jobType = null; // 2012-10-03 by kjt: Added missing logic to create barcodes using sequencing controller as example. // Added 2013-10-03 by kjt Stage stage = null; if (id.HasValue) { jobType = _repositoryFactory.JobTypeRepository.GetNullableById(id.Value); // check the job type if (!jobType.Genotyping) { Message = "Invalid job type specified"; return(RedirectToAction("Create")); } // Added 2013-10-03 by kjt stage = _repositoryFactory.StageRepository.GetNullableById(StageIds.UgWebSubmittedPlates); postModel.JobType = jobType; } ValidateGenotyping(postModel); if (ModelState.IsValid) { var userJob = new UserJob(); AutoMapper.Mapper.Map(postModel, userJob); userJob.UserJobGenotyping = new UserJobGenotyping(); userJob.User = GetCurrentUser(true); userJob.RechargeAccount = postModel.RechargeAccount; foreach (var did in postModel.Dyes) { userJob.UserJobGenotyping.Dyes.Add(_repositoryFactory.DyeRepository.GetById(did)); } foreach (var name in postModel.PlateNames) { var plate = new UserJobPlate() { Name = name }; // Added 2013-10-03 by kjt var barcode = new Barcode() { Stage = stage }; // Added 2013-10-03 by kjt plate.AddBarcode(barcode); userJob.AddUserJobPlates(plate); } _repositoryFactory.UserJobRepository.EnsurePersistent(userJob); Message = "Your job request has been successfully submitted."; return(RedirectToAction("Index", "Authorized")); } var user = GetCurrentUser(); var viewModel = GenotypingViewModel.Create(_repositoryFactory, user, jobType, postModel); return(View(viewModel)); }