Example #1
0
        private void ValidateVector(QbotPostModel postModel)
        {
            if (postModel.Vector == null)
            {
                ModelState.AddModelError("PostModel.Vector", "Vector is required.");
            }

            if (postModel.Vector != null && postModel.Vector.IsOther())
            {
                if (string.IsNullOrEmpty(postModel.NewVector))
                {
                    ModelState.AddModelError("PostModel.NewVector", "New Vector name is required.");
                }

                if (postModel.VectorType == null)
                {
                    ModelState.AddModelError("PostModel.VectorType", "Vector Type is required.");
                }

                if (postModel.Antibiotic1 == null)
                {
                    ModelState.AddModelError("PostModel.Antibiotic1", "Antibiotic is required.");
                }

                if (postModel.Antibiotic2 == null)
                {
                    ModelState.AddModelError("PostModel.Antibiotic2", "Antibiotic is required.");
                }
            }
        }
Example #2
0
        private void ValidateGridding(QbotPostModel postModel)
        {
            if (!postModel.NumPlates.HasValue)
            {
                ModelState.AddModelError("PostModel.NumPlates", "Number of plates is required.");
            }
            else if (postModel.NumPlates.Value <= 0)
            {
                ModelState.AddModelError("PostModel.NumPlates", "You must specify at least one plate.");
            }

            if (!postModel.NumMembranecopies.HasValue)
            {
                ModelState.AddModelError("PostModel.NumMembranecopies", "Number of membrane copies is required.");
            }
            else if (postModel.NumMembranecopies.Value <= 0)
            {
                ModelState.AddModelError("PostModel.NumMembranecopies", "You must specify at least one membrane copy.");
            }

            if (!postModel.GriddingPattern.HasValue)
            {
                ModelState.AddModelError("PostModel.GriddingPattern", "Gridding pattern is required.");
            }

            ValidateVector(postModel);
            ValidateStrain(postModel);
        }
Example #3
0
        private void ValidateReplicating(QbotPostModel postModel)
        {
            if (!postModel.PlateType.HasValue)
            {
                ModelState.AddModelError("PostModel.PlateType", "Plate type is required.");
            }

            if (!postModel.DestinationPlateType.HasValue)
            {
                ModelState.AddModelError("PostModel.DestinationPlateType", "Destination Plate type is required.");
            }

            if (!postModel.SourcePlates.HasValue)
            {
                ModelState.AddModelError("PostModel.SourcePlates", "Number of source plates is required.");
            }
            else if (postModel.SourcePlates.Value <= 0)
            {
                ModelState.AddModelError("PostModel.SourcePlates", "You must specify at least one source plate.");
            }

            if (!postModel.NumCopies.HasValue)
            {
                ModelState.AddModelError("PostModel.NumCopies", "Number of copies is required.");
            }
            else if (postModel.NumCopies.Value <= 0)
            {
                ModelState.AddModelError("PostModel.NumCopies", "You must specify at least one copy.");
            }

            ValidateVector(postModel);
            ValidateStrain(postModel);
        }
Example #4
0
        private bool SaveColonyPicking(QbotPostModel postModel)
        {
            ValidateColonyPicking(postModel);

            if (ModelState.IsValid)
            {
                var userJob = new UserJob();
                var userJobColonyPicking = new UserJobQbotColonyPicking();

                AutoMapper.Mapper.Map(postModel, userJob);
                AutoMapper.Mapper.Map(postModel, userJobColonyPicking);
                userJob.UserJobQbotColonyPicking = userJobColonyPicking;
                userJob.User            = GetCurrentUser(true);
                userJob.RechargeAccount = postModel.RechargeAccount;

                if (postModel.Strain.IsOther())
                {
                    var strain = new Strain()
                    {
                        Name = postModel.NewStrain, Bacteria = postModel.Bacteria, Supplied = false
                    };
                    userJob.UserJobQbotColonyPicking.Strain = strain;
                }

                if (postModel.Vector.IsOther())
                {
                    var vector = new Vector()
                    {
                        Name = postModel.NewVector, VectorType = postModel.VectorType, Antibiotic1 = postModel.Antibiotic1, Antibiotic2 = postModel.Antibiotic2
                    };
                    userJob.UserJobQbotColonyPicking.Vector = vector;
                }

                // add plate
                var stage   = _repositoryFactory.StageRepository.GetNullableById(StageIds.QpWebSubmittedPlates);
                var barcode = new Barcode()
                {
                    Stage = stage
                };
                var userJobPlate = new UserJobPlate()
                {
                    Name = userJob.Name
                };
                userJobPlate.AddBarcode(barcode);
                userJob.AddUserJobPlates(userJobPlate);

                _repositoryFactory.UserJobRepository.EnsurePersistent(userJob);

                return(true);
            }

            return(false);
        }
Example #5
0
        public ActionResult Create(int?id, QbotPostModel postModel)
        {
            JobType jobType = null;

            if (id.HasValue)
            {
                jobType = _repositoryFactory.JobTypeRepository.GetNullableById(id.Value);

                // check the job type
                if (!jobType.Qbot)
                {
                    Message = "Invalid job type specified";
                    return(RedirectToAction("Create"));
                }

                postModel.JobType = jobType;
            }

            var result = false;

            switch (jobType.Id)
            {
            case (int)JobTypeIds.QbotColonyPicking:
                result = SaveColonyPicking(postModel);
                break;

            case (int)JobTypeIds.QbotPlateReplicating:
                result = SaveReplicating(postModel);
                break;

            case (int)JobTypeIds.QbotGridding:
                result = SaveGridding(postModel);
                break;
            }

            if (result)
            {
                Message = "Saved!";
                return(RedirectToAction("Index", "Authorized"));
            }

            var user      = GetCurrentUser();
            var viewModel = QbotViewModel.Create(_repositoryFactory, user, jobType, postModel);

            return(View(viewModel));
        }
Example #6
0
        private void ValidateStrain(QbotPostModel postModel)
        {
            if (postModel.Strain == null)
            {
                ModelState.AddModelError("PostModel.Strain", "Host is required.");
            }

            if (postModel.Strain != null && postModel.Strain.IsOther())
            {
                if (string.IsNullOrEmpty(postModel.NewStrain))
                {
                    ModelState.AddModelError("PostModel.NewStrain", "New Host Name is required.");
                }

                if (postModel.Bacteria == null)
                {
                    ModelState.AddModelError("PostModel.Bacteria", "Bacteria is required.");
                }
            }
        }
Example #7
0
        private void ValidateColonyPicking(QbotPostModel postModel)
        {
            if (!postModel.PlateType.HasValue)
            {
                ModelState.AddModelError("PostModel.PlateType", "Plate Type is required.");
            }

            if (!postModel.Replication.HasValue)
            {
                ModelState.AddModelError("PostModel.Replication", "Replication value is required.");
            }

            if (!postModel.NumColonies.HasValue)
            {
                ModelState.AddModelError("PostModel.NumColonies", "Colonies expected is required.");
            }

            ValidateVector(postModel);
            ValidateStrain(postModel);
        }
Example #8
0
        public static QbotViewModel Create(IRepositoryFactory repositoryFactory, User user, JobType jobType = null, QbotPostModel postModel = null)
        {
            var viewModel = new QbotViewModel()
                {
                    JobType = jobType,
                    JobTypes = jobType == null ? repositoryFactory.JobTypeRepository.Queryable.Where(a => a.Qbot).ToList() : new List<JobType>(),
                    PostModel = postModel ?? new QbotPostModel()
                };

            if (jobType != null)
            {
                var rid = postModel != null && postModel.RechargeAccount != null ? postModel.RechargeAccount.Id : -1;
                viewModel.RechargeAccounts = new SelectList(user.RechargeAccounts, "Id", "AccountNum", rid);

                var vid = postModel != null && postModel.Vector != null ? postModel.Vector.Id : -1;
                viewModel.Vectors = new SelectList(repositoryFactory.VectorRepository.Queryable.OrderByDescending(a => a.Name), "Id", "Name", vid);

                var sid = postModel != null && postModel.Strain != null ? postModel.Strain.Id : -1;
                viewModel.Strains = new SelectList(repositoryFactory.StrainRepository.Queryable.Where(a => a.Supplied), "Id", "Name", sid);

                var vtid = postModel != null && postModel.VectorType != null ? postModel.VectorType.Id : -1;
                viewModel.VectorTypes = new SelectList(repositoryFactory.VectorTypeRepository.GetAll(), "Id", "Name", vtid);

                var ab1 = postModel != null && postModel.Antibiotic1 != null ? postModel.Antibiotic1.Id : -1;
                viewModel.Antibiotic1 = new SelectList(repositoryFactory.AntibioticRepository.Queryable.OrderBy(a => a.Name), "Id", "Name", ab1);

                var ab2 = postModel != null && postModel.Antibiotic2 != null ? postModel.Antibiotic2.Id : -1;
                viewModel.Antibiotic2 = new SelectList(repositoryFactory.AntibioticRepository.Queryable.OrderBy(a => a.Name), "Id", "Name", ab2);

                var bid = postModel != null && postModel.Bacteria != null ? postModel.Bacteria.Id : -1;
                viewModel.Bacterias = new SelectList(repositoryFactory.BacteriaRepository.GetAll(), "Id", "Name", bid);

                if (jobType.Id == (int)JobTypeIds.QbotColonyPicking)
                {
                    var pid = postModel != null ? postModel.PlateType : null;

                    var pts = new List<SelectListItem>();
                    pts.Add(new SelectListItem() { Value = ((int)Core.Resources.PlateTypes.QTray).ToString(), Text = EnumUtility.GetEnumDescription(Core.Resources.PlateTypes.QTray) });
                    pts.Add(new SelectListItem() { Value = ((int)Core.Resources.PlateTypes.GlycerolStock).ToString(), Text = EnumUtility.GetEnumDescription(Core.Resources.PlateTypes.GlycerolStock) });
                    viewModel.PlateTypes = new SelectList(pts, "Value", "Text", pid);
                }

                if (jobType.Id == (int)JobTypeIds.QbotPlateReplicating || jobType.Id == (int)JobTypeIds.QbotGridding)
                {
                    var pid = postModel != null ? postModel.PlateType : null;

                    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", pid);
                }

                if (jobType.Id == (int)JobTypeIds.QbotPlateReplicating)
                {
                    var pid = postModel != null ? postModel.DestinationPlateType : null;

                    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.DestinationPlateTypes = new SelectList(pts, "Value", "Text", pid);
                }

                if (jobType.Id == (int)JobTypeIds.QbotGridding)
                {
                    var pid = postModel != null ? postModel.GriddingPattern : null;

                    var pts = new List<SelectListItem>();
                    pts.Add(new SelectListItem(){ Value=((int)GriddingPattern.ThreeXThree).ToString(), Text = EnumUtility.GetEnumDescription(GriddingPattern.ThreeXThree)});
                    pts.Add(new SelectListItem() { Value = ((int)GriddingPattern.FourXFour).ToString(), Text = EnumUtility.GetEnumDescription(GriddingPattern.FourXFour) });
                    pts.Add(new SelectListItem() { Value = ((int)GriddingPattern.FiveXFive).ToString(), Text = EnumUtility.GetEnumDescription(GriddingPattern.FiveXFive) });

                    viewModel.GriddingPatterns = new SelectList(pts, "Value", "Text", pid);
                }
            }

            return viewModel;
        }