Esempio n. 1
0
        public IEnumerable <Models.Company> GetListCompany()
        {
            string        connectionString = configuration.GetConnectionString("DefaultConnectionString");
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();
            SqlCommand command = new SqlCommand("SELECT * FROM company", connection);

            List <Models.Company> listCompany = new List <Models.Company>();


            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Models.Company company = new Models.Company();
                    company.Id   = (int)reader["id"];
                    company.Name = (string)reader["name"];
                    company.Size = (int)reader["size"];
                    company.FormIncorporation = (string)reader["form_incorporation"];
                    listCompany.Add(company);
                }
            }

            reader.Close();
            connection.Close();

            return(listCompany);
        }
        public Company GetCompany()
        {
            var company = new Company
            {
                Name = this.GetStringItem(this.companyNamesFirstWords) + " " +
                        this.GetStringItem(this.companyNamesSecondWords) + " " +
                        this.GetStringItem(this.companyTypes),
                Rating = random.Next(10, 51),
                Votes = 10 
            };

            return company;
        }
Esempio n. 3
0
        public ActionResult <Models.Company> EditCompany([FromBody] Models.Company company)
        {
            if (ModelState.IsValid)
            {
                string        connectionString = configuration.GetConnectionString("DefaultConnectionString");
                SqlConnection connection       = new SqlConnection(connectionString);
                connection.Open();
                string     sqlExpression = "UPDATE company SET name='" + company.Name + "', size=" + company.Size + ", form_incorporation='" + company.FormIncorporation + "' WHERE id=" + company.Id;
                SqlCommand command       = new SqlCommand(sqlExpression, connection);
                command.ExecuteNonQuery();
                connection.Close();

                return(Ok());
            }
            return(BadRequest());
        }
Esempio n. 4
0
        public ActionResult <Models.Company> AddCompany([FromBody] Models.Company company)
        {
            if (ModelState.IsValid)
            {
                string        connectionString = configuration.GetConnectionString("DefaultConnectionString");
                SqlConnection connection       = new SqlConnection(connectionString);
                connection.Open();
                string     sqlExpression = "INSERT INTO company (name, size, form_incorporation) VALUES ('" + company.Name + "', " + company.Size + ", '" + company.FormIncorporation + "')";
                SqlCommand command       = new SqlCommand(sqlExpression, connection);
                command.ExecuteNonQuery();
                connection.Close();

                return(Ok());
            }
            return(BadRequest());
        }