private void Lekeres_Click(object sender, RoutedEventArgs e)
        {
            if (UgyfelCB.SelectedItem == null || VasaroltAruCB.SelectedItem == null || darabCB.SelectedItem == null || _aruService.Elerheto(int.Parse(VasaroltAruCB.SelectedItem.ToString().Split(' ')[0])) == 0 || HataridoDP.SelectedDate == null)
            {
                MessageBox.Show("Kötelező minden elemet kiválasztani!");
                return;
            }
            teljesarL.Content = "";
            Kapcsolat temp = new Kapcsolat();

            temp.UgyfelID = _ugyfelService.GetByID(int.Parse(UgyfelCB.SelectedItem.ToString().Split(' ')[0])).ResponseObject.Id;
            temp.AruID    = _aruService.GetByID(int.Parse(VasaroltAruCB.SelectedItem.ToString().Split(' ')[0])).ResponseObject.Id;
            temp.Darab    = int.Parse(darabCB.SelectedItem.ToString());
            temp.HatarIdo = DateTime.Parse(HataridoDP.SelectedDate.ToString());
            temp.TeljesAr = Convert.ToInt16(_aruService.GetByID(int.Parse(VasaroltAruCB.SelectedItem.ToString().Split(' ')[0])).ResponseObject.Ar) * int.Parse(darabCB.SelectedItem.ToString());
            DateTime val = _kapcsolatService.Create(temp).ResponseObject.Datum;

            if (val != null)
            {
                Aru gep = new Aru(_aruService.GetByID(temp.AruID).ResponseObject);
                gep.Mennyiseg -= temp.Darab;
                _aruService.Update(gep);
                MessageBox.Show("Sikeres vásárlás rögzítés!");
                Frissit(int.Parse(VasaroltAruCB.SelectedItem.ToString().Split(' ')[0]));
                FeltoltLista();
            }

            else
            {
                MessageBox.Show("Hiba a vásárlás rögzítésében!");
            }
        }
        public Kapcsolat GetByID(int id)
        {
            Kapcsolat result = null;

            using (SqlConnection connection = new SqlConnection(Connection.String))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "KapcsolatByID";

                command.Parameters.Add(new SqlParameter("@Id", id));

                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        result = Mapentity(reader);
                    }
                }
            }

            return(result);
        }
        public Kapcsolat Create(Kapcsolat entity)
        {
            using (SqlConnection connection = new SqlConnection(Connection.String))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "CreateKapcsolat";

                command.Parameters.Add(new SqlParameter("@UgyfelID", entity.UgyfelID));
                command.Parameters.Add(new SqlParameter("@AruID", entity.AruID));
                command.Parameters.Add(new SqlParameter("@Darab", entity.Darab));
                command.Parameters.Add(new SqlParameter("@HatarIdo", entity.HatarIdo));
                command.Parameters.Add(new SqlParameter("@TeljesAr", entity.TeljesAr));

                connection.Open();
                int result = (int)command.ExecuteScalar();
                if (result < 1)
                {
                    throw new Exception("Error in CreateKapcsolat stored procedure.");
                }

                entity.ID = (int)result;
                return(entity);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var db = new Kapcsolat();

            Console.WriteLine($"Mennyi rekord van az autok táblában: {db.Autos.Count()}");

            Console.ReadLine();
        }
        private Kapcsolat Mapentity(SqlDataReader data)
        {
            Kapcsolat result = new Kapcsolat();

            result.AruID    = int.Parse(data["AruID"].ToString());
            result.UgyfelID = int.Parse(data["UgyfelID"].ToString());
            result.Datum    = DateTime.Parse(data["Datum"].ToString());
            result.HatarIdo = DateTime.Parse(data["HatarIdo"].ToString());
            result.Darab    = int.Parse(data["Darab"].ToString());
            result.TeljesAr = int.Parse(data["TeljesAr"].ToString());

            return(result);
        }
Example #6
0
        public ResponseMessage <Kapcsolat> Create(Kapcsolat entity)
        {
            ResponseMessage <Kapcsolat> response = new ResponseMessage <Kapcsolat>();

            try
            {
                response.ResponseObject = _kapcsolatRepository.Create(entity);
                response.IsSuccess      = true;
                response.ErrorMessage   = "Success";
            }

            catch (Exception ex)
            {
                response.IsSuccess    = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }