Esempio n. 1
0
        public async Task <IActionResult> PutAuto(int id, Auto auto)
        {
            if (id != auto.ModellId)
            {
                return(BadRequest());
            }

            var gyartoId = await _context.Gyartok.Where(gy => gy.GyartoNev.ToUpper() == auto.GyartoNev.ToUpper()).Select(gy => gy.Id).FirstOrDefaultAsync();

            if (gyartoId == 0)
            {
                var newGyarto = new Gyarto
                {
                    GyartoNev = auto.GyartoNev
                };
                _context.Gyartok.Add(newGyarto);
                await _context.SaveChangesAsync();

                gyartoId = newGyarto.Id;
            }

            var reszletek = new Reszletek
            {
                Id           = auto.ReszletekId,
                Ajtok        = auto.Ajtok,
                Teljesitmeny = auto.Teljesitmeny,
                Ulesek       = auto.Ulesek,
                Evjarat      = auto.Evjarat
            };

            _context.Entry(reszletek).State = EntityState.Modified;

            var modell = new Modell
            {
                Id          = auto.ModellId,
                ModellNev   = auto.ModellNev,
                GyartoId    = gyartoId,
                ReszletekId = reszletek.Id
            };

            _context.Entry(modell).State = EntityState.Modified;


            await _context.SaveChangesAsync();


            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutDbCarDetail(int id, DbCarDetail dbCarDetail)
        {
            if (id != dbCarDetail.ID)
            {
                return(BadRequest());
            }

            _context.Entry(dbCarDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbCarDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }