Exemplo n.º 1
0
        public void Put(Roast roast)
        {
            _logger.LogInformation("Update roast information: {roast}");
            // get roast from database
            var dbRoasts = _context.Roasts.Include(x => x.Beans).ThenInclude(x => x.StockItem);
            var dbRoast  = dbRoasts.FirstOrDefault(x => x.Id == roast.Id);

            //List<GreenBlend> blendsToRemove = new List<GreenBlend>();
            // remove items, which are not yet needed anymore
            foreach (var bl in dbRoast.Beans)
            {
                if (!roast.Beans.Select(x => x.Id).Contains(bl.Id))
                {
                    //blendsToRemove.Add(bl);
                    var sbl = _context.GreenBlends.FirstOrDefault(x => x.Id == bl.Id);
                    _context.GreenBlends.Remove(sbl);
                }
            }
            _context.SaveChanges();

            List <GreenBlend> blend = new List <GreenBlend>();

            // add new items
            foreach (var bl in roast.Beans)
            {
                var b = _context.GreenBlends.FirstOrDefault(x => x.Id == bl.Id);
                blend.Add(b);
            }
            dbRoast.Beans = blend;
            _context.Entry(dbRoast).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();
        }
Exemplo n.º 2
0
 public void Put(Stock stock)
 {
     _logger.LogInformation("Update stock information: {stock}");
     stock.GreenBeanInfo         = _context.GreenBeanInfos.FirstOrDefault(x => x.Id == stock.GreenBeanInfo.Id);
     stock.SellerContact         = _context.Contacts.FirstOrDefault(x => x.Id == stock.SellerContact.Id);
     _context.Entry(stock).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }
Exemplo n.º 3
0
 public void Put(Cupping cupping)
 {
     _logger.LogInformation("Update cupping: {cupping}");
     _context.Entry(cupping).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }
 public void Put(GreenBeanInfo greenBeanInfo)
 {
     _logger.LogInformation("Update GreenBeanInfo: {greenBeanInfo}");
     _context.Entry(greenBeanInfo).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }
Exemplo n.º 5
0
 public void Put(Contact contact)
 {
     _logger.LogInformation("Update contact: {contact}");
     _context.Entry(contact).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _context.SaveChanges();
 }