Exemplo n.º 1
0
        //public void Put(int id, [FromBody] string value)
        public string Update(long id, [FromBody] JObject body)
        {
            var interventions = _context.Interventions.Find(id);

            if (interventions == null)
            {
                return("Return a valid Id");
            }
            var previous_status = interventions.Status;
            var status          = (string)body.SelectToken("status");

            if (status == "inProgess")
            {
                DateTime time = DateTime.Now;
                interventions.Status     = status;
                interventions.Start      = DateTime.Now;
                interventions.Updated_At = DateTime.Now;
                _context.Interventions.Update(interventions);
                _context.SaveChanges();
                return("Interventions #" + interventions.Id + " Has now changed status from " + previous_status + " to " + status + ".");
            }
            {
                if (status == "complete")
                {
                    DateTime time = DateTime.Now;
                    interventions.Status     = status;
                    interventions.End        = DateTime.Now;
                    interventions.Created_At = DateTime.Now;
                    _context.Interventions.Update(interventions);
                    _context.SaveChanges();
                    return("Interventions #" + interventions.Id + " Has now changed status from " + previous_status + " to " + status + ".");
                }
                else
                {
                    return("Invalid Status");
                }
            }
        }
        //public void Put(int id, [FromBody] string value)
        public IActionResult Update(long id, Columns item)
        {
            var change = _context.Columns.Find(id);

            if (change == null)
            {
                return(NotFound());
            }
            //change.IsComplete = item.IsComplete;
            change.Status = item.Status;

            _context.Columns.Update(change);
            _context.SaveChanges();
            return(NoContent());
        }