Exemplo n.º 1
0
 public bool Edit(NewspaperName name)
 {
     if (validation.Validate(name).Count > 0)
     {
         foreach (var res in validation.Validate(name))
         {
             if (res.IsValidate)
             {
                 logger.Error(res.ValidationMessage.ToString());
             }
         }
     }
     return(nameDao.Edit(name));
 }
Exemplo n.º 2
0
        public List <ValidationResult> Validate(NewspaperName newspaperName)
        {
            List <ValidationResult> results = new List <ValidationResult>();

            if (newspaperName == null)
            {
                results.Add(new ValidationResult(true, new ArgumentNullException(nameof(newspaperName)).Message.ToString()));
            }

            if (string.IsNullOrWhiteSpace(newspaperName.Name))
            {
                results.Add(new ValidationResult(true, new ArgumentException("Name").Message.ToString()));
            }

            return(results);
        }
Exemplo n.º 3
0
 public bool Edit(NewspaperName newspaper)
 {
     try
     {
         using (var con = new SqlConnection(config.ConnectionString))
         {
             using (var cmnd = new SqlCommand("newspaper_name_edite", con))
             {
                 cmnd.CommandType = CommandType.StoredProcedure;
                 cmnd.Parameters.AddWithValue("@name", newspaper.Name);
                 cmnd.Parameters.AddWithValue("@id", newspaper.Id);
                 con.Open();
                 cmnd.ExecuteNonQuery();
                 return true;
             }
         }
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 4
0
        public bool Add(NewspaperName newspaper)
        {
            if (newspaper == null)
            {
                throw new ArgumentNullException();
            }

            if (newspaper.Name == null || newspaper.Name.Length > 300)
            {
                throw new ArgumentException("NewspaperName Name");
            }

            try
            {
                using (var con = new SqlConnection(config.ConnectionString))
                {
                    using (var cmnd = new SqlCommand("newspaper_name_add", con))
                    {
                        cmnd.CommandType = CommandType.StoredProcedure;
                        cmnd.Parameters.AddWithValue("@name", newspaper.Name);
                        cmnd.Parameters.Add("@id", SqlDbType.Int, 4);
                        cmnd.Parameters["@id"].Direction = ParameterDirection.Output;
                        con.Open();
                        cmnd.ExecuteNonQuery();
                        int? id = cmnd.Parameters["@id"].Value as int?;
                        if (id != null)
                        {
                            newspaper.Id = (int)cmnd.Parameters["@id"].Value;
                        }
                        return true;
                    }
                }
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 5
0
        public ICollection<NewspaperName> GetAll()
        {
            using (var con = new SqlConnection(config.ConnectionString))
            {
                using (var cmnd = new SqlCommand("newspapers_names_get_all", con))
                {
                    cmnd.CommandType = CommandType.StoredProcedure;
                    con.Open();

                    using (var reader = cmnd.ExecuteReader())
                    {
                        var newspapersNames = new List<NewspaperName>();
                        while (reader.Read())
                        {
                            var newspaper = new NewspaperName();
                            newspaper.Id = (int)reader["id"];
                            newspaper.Name = (string)reader["name"];
                            newspapersNames.Add(newspaper);
                        }
                        return newspapersNames;
                    }
                }
            }
        }