public async Task <IActionResult> PutOrder(int id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #2
0
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
Beispiel #3
0
        public async Task <IActionResult> PutTinplate(long id, TinplateStatus newStatus)
        {
            Tinplate tinplate = _context.Tinplates.Find(id);

            if (tinplate == null)
            {
                return(NotFound());
            }

            //prevent double Production/Consumed
            if (tinplate.TinplateStatus >= newStatus)
            {
                return(BadRequest());
            }
            var currentUser = "******";

            tinplate.UpdateTime = DateTime.Now;

            if (newStatus == TinplateStatus.Production)
            {
                //check if there are any Tinplate in plant
                if (_context.Tinplates.Any(t => t.TinplateStatus == newStatus))
                {
                    Tinplate prevTinplate = _context.Tinplates.FirstOrDefault(t => t.TinplateStatus == newStatus);
                    prevTinplate.TinplateStatus = TinplateStatus.Consumed;

                    var preNewNote = $"On {tinplate.UpdateTime}, this pallet of tinplate has been used, operator: {currentUser}.\n";
                    prevTinplate.Note += preNewNote;

                    _context.Entry(prevTinplate).State = EntityState.Modified;
                }

                tinplate.TinplateStatus = TinplateStatus.Production;
                //log the activities history
                var newNote = $"On {tinplate.UpdateTime}, this pallet of tinplate has been using, operator: {currentUser}.\n";
                tinplate.Note += newNote;
            }
            else if (newStatus == TinplateStatus.Consumed)
            {
                tinplate.TinplateStatus = TinplateStatus.Consumed;
                //log the activities history
                var newNote = $"On {tinplate.UpdateTime}, this pallet of tinplate has been used, operator: {currentUser}.\n";
                tinplate.Note += newNote;
            }

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

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

            return(NoContent());
        }