Ejemplo n.º 1
0
        public static string FilterList(int companyId, long processId, long ruleId, string apartadoNorma)
        {
            var res    = new List <Questionary>();
            var source = string.Format(CultureInfo.InvariantCulture, @"Questionary==>Filter({0}),", companyId);

            using (var cmd = new SqlCommand("Cuestionario_Filter"))
            {
                using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
                {
                    cmd.Connection  = cnn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(DataParameter.Input("@CompanyId", companyId));
                    cmd.Parameters.Add(DataParameter.Input("@ProcessId", processId));
                    cmd.Parameters.Add(DataParameter.Input("@RuleId", ruleId));
                    cmd.Parameters.Add(DataParameter.Input("@ApartadoNorma", apartadoNorma, 50));
                    try
                    {
                        cmd.Connection.Open();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                var newQuestionary = new Questionary
                                {
                                    Id            = rdr.GetInt64(ColumnsQuestionaryGet.Id),
                                    Description   = rdr.GetString(ColumnsQuestionaryGet.Description),
                                    ApartadoNorma = rdr.GetString(ColumnsQuestionaryGet.ApartadoNorma),
                                    Notes         = rdr.GetString(ColumnsQuestionaryGet.Notes),
                                    Rule          = new Rules
                                    {
                                        Id          = rdr.GetInt64(ColumnsQuestionaryGet.NormaId),
                                        Description = rdr.GetString(ColumnsQuestionaryGet.NormaDescription)
                                    },
                                    Process = new Process
                                    {
                                        Id          = rdr.GetInt64(ColumnsQuestionaryGet.ProcessId),
                                        Description = rdr.GetString(ColumnsQuestionaryGet.ProcessDescription)
                                    },
                                    CreatedBy = new ApplicationUser
                                    {
                                        Id       = rdr.GetInt32(ColumnsQuestionaryGet.CreatedBy),
                                        UserName = rdr.GetString(ColumnsQuestionaryGet.CreatedByName)
                                    },
                                    CreatedOn  = rdr.GetDateTime(ColumnsQuestionaryGet.CreatedOn),
                                    ModifiedBy = new ApplicationUser
                                    {
                                        Id       = rdr.GetInt32(ColumnsQuestionaryGet.ModifiedBy),
                                        UserName = rdr.GetString(ColumnsQuestionaryGet.ModifiedByName)
                                    },
                                    ModifiedOn = rdr.GetDateTime(ColumnsQuestionaryGet.ModifiedOn),
                                    Active     = rdr.GetBoolean(ColumnsQuestionaryGet.Active),
                                    NQuestions = rdr.GetInt32(ColumnsQuestionaryGet.NQuestions)
                                };

                                res.Add(newQuestionary);
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (FormatException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (NullReferenceException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }

            return(JsonList(new ReadOnlyCollection <Questionary>(res)));
        }
Ejemplo n.º 2
0
        /// <summary>Gets a descriptive string with the differences between two questionaries</summary>
        /// <param name="other">Second process to compare</param>
        /// <returns>A descriptive string</returns>
        public string Differences(Questionary other)
        {
            if (this == null || other == null)
            {
                return(string.Empty);
            }

            var  res   = new StringBuilder();
            bool first = true;

            if (this.Description != other.Description)
            {
                res.Append("Description:").Append(other.Description);
                first = false;
            }

            if (this.Rule.Id != other.Rule.Id)
            {
                if (!first)
                {
                    res.Append(",");
                }

                res.Append("rule:").Append(other.Rule.Id);
                first = false;
            }

            if (this.Process != other.Process)
            {
                if (!first)
                {
                    res.Append(",");
                }

                res.Append("ProcessType:").Append(other.Process.Description);
            }

            if (this.ApartadoNorma != other.ApartadoNorma)
            {
                if (!first)
                {
                    res.Append(",");
                }

                res.Append("ApartadoNorma:").Append(other.ApartadoNorma);
                first = false;
            }

            if (this.Notes != other.Notes)
            {
                if (!first)
                {
                    res.Append(",");
                }

                res.Append("Notes:").Append(other.Notes);
                first = false;
            }

            return(res.ToString());
        }