Example #1
0
        public ActionResult UpdateSolution(int id, [FromBody] SolutionRequest item)
        {
            if (item == null || !ModelState.IsValid)
            {
                return(BadRequest("Model state not valid."));
            }

            if (id != item.ID)
            {
                return(BadRequest("ID not valid."));
            }

            var now = DateTime.UtcNow;

            var solution = new Solution
            {
                ID         = id,
                Title      = item.Title,
                UpdatedBy  = "Oscar Negrete",
                LastUpdate = now
            };

            try
            {
                _solutionService.UpdateSolution(solution);
            }
            catch (Exception e)
            {
                if (!_solutionService.SolutionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest(e.Message));
                }
            }

            return(Ok($"Solution updated: {solution.ID} - {solution.Title}"));
        }