Ejemplo n.º 1
0
        public async Task <SalesPersons> Update(SalesPersons sales)
        {
            _context.Update(sales);
            await _context.SaveChangesAsync();

            return(sales);
        }
Ejemplo n.º 2
0
        public List <SalesPersons> GetAllPersons()
        {
            List <SalesPersons> sp = new List <SalesPersons>();
            string com             = "SELECT * FROM SalesPersons";

            using (SqlConnection con = new SqlConnection(ConString))
            {
                con.Open();
                using (SqlCommand command = new SqlCommand(com, con))
                {
                    DataSet        ds = new DataSet();
                    SqlDataAdapter a  = new SqlDataAdapter(command);

                    a.Fill(ds);

                    foreach (DataTable table in ds.Tables)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            SalesPersons p = new SalesPersons(row.Field <string>("Fornavn"), row.Field <string>("Efternavn"), row.Field <string>("Initialer"), row.Field <int>("PersonID"));
                            if (p.ValidateData())
                            {
                                sp.Add(p);
                            }
                            else
                            {
                                throw new Exception("A name on the list['SalesPersons'] does not compute.");
                            }
                        }
                    }
                }
            }
            return(sp);
        }
Ejemplo n.º 3
0
        private void btnNewCar_Click(object sender, RoutedEventArgs e)
        {
            SalesPersons p = (SalesPersons)cBoxEmployeeNames.SelectedItem;

            try
            {
                int stel  = Int32.Parse(tBoxNewCarStelnummer.Text);
                int reg   = Int32.Parse(tBoxNewCarRegistreringsnummer.Text);
                int trans = Int32.Parse(tBoxTransaktionsbeløb.Text);

                bool ny   = (bool)chkBoxNewCarNew.IsChecked;
                bool ejet = (bool)chkBoxEjet.IsChecked;
                Car  c    = new Car(stel, tBoxNewCarMaerke.Text, tBoxNewCarModel.Text, reg, ny);
                Sale s    = new Sale(0, trans, ejet, p, c);

                if (p.ValidateData() && c.ValidateData() && s.ValidateData())
                {
                    if (dbh.AddNewCar(c) && dbh.AddNewSale(c, p, trans, ejet))
                    {
                        MessageBox.Show("En ny transaktion er blevet oprettet.", "succes");
                    }
                    else
                    {
                        MessageBox.Show("Et eller flere problemer opstod under processen.", "Ups!");
                    }
                }
            } catch
            {
                ValidateInput();
            }
        }
Ejemplo n.º 4
0
        public async Task <SalesPersons> Add(SalesPersons sales)
        {
            await _context.SalesPersons.AddAsync(sales);

            await _context.SaveChangesAsync();

            return(sales);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutSalesPersons(int id, SalesPersons salesPersons)
        {
            if (id != salesPersons.SalesPersonsId)
            {
                return(BadRequest());
            }

            await _salesPersonRepository.Update(salesPersons);

            return(NoContent());
        }
Ejemplo n.º 6
0
        public List <Sale> GetAllSales()
        {
            List <Sale> sales = new List <Sale>();
            string      com   = "SELECT * FROM Sale";

            using (SqlConnection con = new SqlConnection(ConString))
            {
                con.Open();
                using (SqlCommand command = new SqlCommand(com, con))
                {
                    DataSet        ds = new DataSet();
                    SqlDataAdapter a  = new SqlDataAdapter(command);

                    a.Fill(ds);

                    foreach (DataTable table in ds.Tables)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            List <SalesPersons> ps     = GetAllPersons();
                            SalesPersons        person = null;
                            foreach (SalesPersons p in ps)
                            {
                                if (p.ID == row.Field <int>("PersonID"))
                                {
                                    person = p;
                                }
                            }

                            List <Car> cs  = GetAllCars();
                            Car        Car = null;
                            foreach (Car c in cs)
                            {
                                if (c.Stelnummer == row.Field <int>("Stelnummer"))
                                {
                                    Car = c;
                                }
                            }

                            Sale s = new Sale(row.Field <int>("ID"), row.Field <int>("Transaktionsbeløb"), row.Field <bool>("Ejet"), person, Car);
                            if (s.ValidateData())
                            {
                                sales.Add(s);
                            }
                            else
                            {
                                throw new Exception("A name on the list['Sales'] does not compute.");
                            }
                        }
                    }
                }
            }
            return(sales);
        }
Ejemplo n.º 7
0
        public bool AddNewSale(Car c, SalesPersons p, int trans, bool ejet)
        {
            int saleRowsAffected;

            string sale = $"INSERT INTO Sale VALUES ({trans}, '{ejet}', {p.ID}, {c.Stelnummer})";

            using (SqlConnection con = new SqlConnection(ConString))
            {
                con.Open();
                using (SqlCommand com = new SqlCommand(sale, con)) {
                    saleRowsAffected = com.ExecuteNonQuery();
                }
            }
            if (saleRowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <SalesPersons> > PostSalesPersons(SalesPersons salesPersons)
        {
            await _salesPersonRepository.Add(salesPersons);

            return(CreatedAtAction("GetSalesPersons", new { id = salesPersons.SalesPersonsId }, salesPersons));
        }