Ejemplo n.º 1
0
        // Attribute specifying to routing layer that PUT is intended (http verb
        public IActionResult Update(string id, Toaster toasterIn)
        // IAction Result is preferable here to ActionResult since the update
        // could result in multiple ActionResult return types.
        // the Put action does the responding, the actionResult method chooses
        // what kind of response
        {
            // model binding is going on here. retrieving/providing/converting/updating
            // data is automated for the action

            var toaster = _toasterService.Get(id);

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

            var oldToaster = _toasterService.Get(id);

            _toasterService.Update(id, toasterIn);


            // running toaster lookup and update with most recent info for log

            // NOTE: it is logically possible for the toaster state to be updated in the DB
            // and still have the logging fail. This is something we can handle in the next iteration.
            EventHandler.HandleToasterStateChange(oldToaster, toasterIn);
            // call logging HandleToaster... function from EventHandler to log
            // the event
            return(NoContent());
        }
Ejemplo n.º 2
0
        public IActionResult Update(string id, Toaster toasterIn)
        {
            var toaster = _toasterService.Get(id);

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

            var oldToaster = _toasterService.Get(id);

            _toasterService.Update(id, toasterIn);

            // NOTE: it is logically possible for the toaster state to be updated in the DB
            // and still have the logging fail. This is something we can handle in the next iteration.
            EventHandler.HandleToasterStateChange(oldToaster, toasterIn);
            return(NoContent());
        }