public IHttpActionResult PostFaturaDetails(int id, Fatura fatura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != fatura.FaturaID)
            {
                return(BadRequest());
            }

            var curFatura    = db.Faturas.FirstOrDefault(x => x.FaturaID == id);
            var silinecekler = new List <FaturaDetay>();

            foreach (var fd in curFatura.FaturaDetays)
            {
                if (fatura.FaturaDetays.FirstOrDefault(x => x.FaturaDetayID == fd.FaturaDetayID) == null)
                {
                    silinecekler.Add(fd);
                }
            }

            foreach (var fd in silinecekler)
            {
                db.FaturaDetays.Remove(fd);
                db.SaveChanges();
            }

            foreach (var fd in fatura.FaturaDetays)
            {
                if (fd.FaturaDetayID == 0)
                {
                    db.FaturaDetays.Add(fd);
                    db.SaveChanges();
                }
                else
                {
                    try
                    {
                        fd.LastModifiedTime = DateTime.Now;
                        db.FaturaDetays.Attach(fd);
                        db.Entry(fd).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    catch {}
                }
            }

            try
            {
                fatura.LastModifiedTime = DateTime.Now;
                db.Entry(fatura).State  = EntityState.Modified;
                db.SaveChanges();
            }
            catch {}
            return(StatusCode(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutRestItem(long id, RestItem restItem)
        {
            if (id != restItem.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutDishItem(long id, DishItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }