Ejemplo n.º 1
0
        /// <summary>
        /// Method to get all the available quality check rules.
        /// </summary>
        /// <param name="includeAdminRules">bool indicates if rules marked as AdminOnly should be returned or not</param>
        /// <returns>Quality check rules collection.</returns>
        public IList<QualityCheckModel> GetQualityCheckRules(bool includeAdminRules)
        {
            IList<QualityCheckModel> lstQCRules = new List<QualityCheckModel>();
            var lstQCModel = this.qualityCheckRepository.RetrieveQualityCheckRules();
            foreach (var qcModel in lstQCModel)
            {
                bool isVisibleToAll = qcModel.IsVisibleToAll.HasValue? (bool)qcModel.IsVisibleToAll: true;
                if (includeAdminRules || isVisibleToAll)
                {
                    QualityCheckModel model = new QualityCheckModel();
                    if (qcModel.QualityCheckColumnRules != null && qcModel.QualityCheckColumnRules.Count > 0)
                    {
                        qcModel.QualityCheckColumnRules = qcModel.QualityCheckColumnRules.OrderBy(qc => qc.Order).ToList();
                    }
                    model.QualityCheckData = qcModel;
                    var user = this.userRepository.GetUserbyUserId(qcModel.CreatedBy);
                    model.CreatedUser = user.FirstName + " " + user.LastName;
                    lstQCRules.Add(model);
                }
            }

            return lstQCRules;
        }
        /// <summary>
        /// Extension method class for quality check rule viewmodel.
        /// </summary>
        /// <param name="rule">Quality check rule view model.</param>
        /// <param name="qualityCheck">Quality check model.</param>
        /// <param name="lstQCColumnTypes">Quality check column types.</param>
        public static void SetValuesFrom(this QCRuleViewModel rule, QualityCheckModel qualityCheck, IEnumerable<QualityCheckColumnType> lstQCColumnTypes)
        {
            Check.IsNotNull<QCRuleViewModel>(rule, "qcRuleViewModel");
            Check.IsNotNull<QualityCheckModel>(qualityCheck, "qualityCheckModel");
            Check.IsNotNull<QualityCheck>(qualityCheck.QualityCheckData, "qualityCheck");

            rule.CreatedDate = qualityCheck.QualityCheckData.CreatedOn.ToClientTime().ToString();
            rule.CreatedUser = qualityCheck.CreatedUser;
            rule.IsOrderRequired = qualityCheck.QualityCheckData.EnforceOrder == null ? false : Convert.ToBoolean(qualityCheck.QualityCheckData.EnforceOrder);
            rule.IsVisibleToAll = qualityCheck.QualityCheckData.IsVisibleToAll == null ? true : Convert.ToBoolean(qualityCheck.QualityCheckData.IsVisibleToAll);
            rule.QCRuleDescription = qualityCheck.QualityCheckData.Description;
            rule.QCRuleId = qualityCheck.QualityCheckData.QualityCheckId;
            rule.QCRuleName = qualityCheck.QualityCheckData.Name;
            rule.CreatedBy = qualityCheck.QualityCheckData.CreatedBy;
            rule.VisibilityOption = (qualityCheck.QualityCheckData.IsVisibleToAll != null && qualityCheck.QualityCheckData.IsVisibleToAll == true) ? 1 : 2;

            foreach (var columnRule in qualityCheck.QualityCheckData.QualityCheckColumnRules)
            {
                QCHeaderViewModel headerModel = new QCHeaderViewModel();
                headerModel.ColumnTypeId = columnRule.QualityCheckColumnTypeId;
                headerModel.ErrorMessage = columnRule.ErrorMessage;
                headerModel.HeaderName = columnRule.HeaderName;
                headerModel.IsRequired = columnRule.IsRequired == null ? false : Convert.ToBoolean(columnRule.IsRequired);
                headerModel.QCColumnRuleId = columnRule.QualityCheckColumnRuleId;
                headerModel.Order = columnRule.Order;
                headerModel.QCColumnTypes = new SelectList(lstQCColumnTypes, "QualityCheckColumnTypeId", "Name", columnRule.QualityCheckColumnTypeId);

                if (!string.IsNullOrWhiteSpace(columnRule.Range))
                {
                    var rangeArray = columnRule.Range.Split(new string[] { Utilities.Constants.RangeSeparator }, StringSplitOptions.None);
                    headerModel.RangeStart = rangeArray[0];
                    headerModel.RangeEnd = rangeArray[1];
                }

                rule.LstHeaderNames.Add(headerModel);
            }
        }
Ejemplo n.º 3
0
        public void Get_Quality_Check_By_Id_Success()
        {
            List<QualityCheckColumnRule> lstCol = new List<QualityCheckColumnRule>();
            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1 desc", ErrorMessage = "error msg", HeaderName = "Column 1", IsActive = true, IsRequired = true, Order = 1, QualityCheck = null, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" };
            QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2 desc", ErrorMessage = "error msg1", HeaderName = "Column 2", IsActive = true, IsRequired = true, Order = 2, QualityCheck = null, QualityCheckColumnRuleId = 2, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "" };

            lstCol.Add(colRule);
            lstCol.Add(colRule1);

            QualityCheckModel model = new QualityCheckModel() { CreatedUser = "******", QualityCheckData = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckColumnRules = lstCol, QualityCheckId = 1 } };

            this.qcService = new StubIQCService()
            {
                GetQualityCheckByIdInt32 = (id) => { return model; }
            };

            QCController qcController = CreateRequest(HttpMethod.Get);

            // Perform
            var response = qcController.GetQualityCheckById(1);

            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Status Code is not as Expected");
            var result = response.Content.ReadAsAsync<QualityCheckModel>().Result;

            Assert.IsNotNull(result, "There is no Quality check rule for the mentioned id");

            Assert.AreEqual(result.CreatedUser, "Test User");
            Assert.AreEqual(result.QualityCheckData.CreatedBy, 1);
            Assert.AreEqual(result.QualityCheckData.Description, "Test Rule");
            Assert.AreEqual(result.QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result.QualityCheckData.IsActive, true);
            Assert.AreEqual(result.QualityCheckData.IsVisibleToAll, true);
            Assert.AreEqual(result.QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result.QualityCheckData.ModifiedBy, 1);
            Assert.AreEqual(result.QualityCheckData.Name, "Test Rule");
            Assert.AreEqual(result.QualityCheckData.QualityCheckId, 1);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to get the quality check object by its id.
        /// </summary>
        /// <param name="qcId">Quality check id.</param>
        /// <returns>Quality check object.</returns>
        public QualityCheckModel GetQualityCheckById(int qcId)
        {
            QualityCheckModel qcRuleModel = new QualityCheckModel();
            var qcModel = this.qualityCheckRepository.GetQualityCheckByID(qcId);

            if (qcModel.QualityCheckColumnRules != null && qcModel.QualityCheckColumnRules.Count > 0)
            {
                qcModel.QualityCheckColumnRules = qcModel.QualityCheckColumnRules.OrderBy(qc => qc.Order).ToList();
            }
            //qcModel.QualityCheckColumnRules = qcModel.QualityCheckColumnRules.OrderBy(qc => qc.Order).ToList();
            qcRuleModel.QualityCheckData = qcModel;
            var user = this.userRepository.GetUserbyUserId(qcModel.CreatedBy);
            qcRuleModel.CreatedUser = user.FirstName + " " + user.LastName;
            return qcRuleModel;
        }