// GET: Bons/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var bon = await _context.Bon.FindAsync(id);

            var kun       = new KundeRepository(_context);
            var bonDetail = new BonDetail()
            {
                Kundes  = kun.GetKundeSelectList(),
                Art     = bon.Art,
                Datum   = bon.Datum,
                ID      = bon.ID,
                KundeID = bon.Kunde.ID
            };
            int idd = bon.Kunde.ID;

            if (bon == null)
            {
                return(NotFound());
            }
            return(View(bonDetail));
        }
Ejemplo n.º 2
0
        internal List <BonDetail> GetBonList()
        {
            List <Bon> bons = new List <Bon>();

            bons = _context.Bon.AsNoTracking()
                   .Include(x => x.Kunde)
                   .ToList();
            if (bons != null)
            {
                List <BonDetail> bonDetail = new List <BonDetail>();
                foreach (var item in bons)
                {
                    var bDetail = new BonDetail()
                    {
                        ID         = item.ID,
                        KundeTitel = item.Kunde.Vorname + " " + item.Kunde.Nachname,
                        Datum      = item.Datum,
                        Art        = item.Art
                    };
                    bonDetail.Add(bDetail);
                }
                return(bonDetail);
            }
            return(null);
        }
        // GET: Bons/Create
        public IActionResult Create()
        {
            var bonDet = new BonDetail();
            var kn     = new KundeRepository(_context);

            bonDet.Kundes = kn.GetKundeSelectList();
            return(View(bonDet));
        }
        public async Task <IActionResult> Create([Bind("ID,Datum,Art,KundeID")] BonDetail bonDet)
        {
            if (ModelState.IsValid)
            {
                var bonnew = new Bon()
                {
                    Art   = bonDet.Art,
                    Datum = bonDet.Datum
                };
                bonnew.Kunde = _context.Kunde.Find(bonDet.KundeID);


                _context.Add(bonnew);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            throw new ApplicationException("Invalid model");
        }
        // GET: Bons/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            //var bon = await _context.Bon.FindAsync(id);
            //var kun = new KundeRepository(_context);
            //var bonDetail = new BonDetail()
            //{
            //    Kundes = kun.GetKundeSelectList(),
            //    Art = bon.Art,
            //    Datum = bon.Datum,
            //    ID = bon.ID,
            //    KundeID = bon.Kunde.ID
            //};

            var bon = await _context.Bon.FindAsync(id);

            var kun       = new KundeRepository(_context);
            var bonDetail = new BonDetail()
            {
                Kundes  = kun.GetKundeSelectList(),
                Art     = bon.Art,
                Datum   = bon.Datum,
                ID      = bon.ID,
                KundeID = bon.Kunde.ID
            };

            // int idd = bon.Kunde.ID;
            BonRepository pr = new BonRepository(_context);

            bonDetail.KundeTitel = pr.GetKundeTitel(bon.Kunde.ID);
            if (bon == null)
            {
                return(NotFound());
            }

            return(View(bonDetail));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Datum,Art,KundeID")] BonDetail bonDet)
        {
            if (id != bonDet.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var bon = new Bon()
                    {
                        ID    = bonDet.ID,
                        Art   = bonDet.Art,
                        Datum = bonDet.Datum
                    };
                    bon.Kunde = _context.Kunde.Find(bonDet.KundeID);
                    _context.Update(bon);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BonExists(bonDet.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bonDet));
        }