Exemplo n.º 1
0
        public IActionResult UpdateTask(Guid id, [FromBody] Entities.Models.Task task)
        {
            try
            {
                if (task == null)
                {
                    return(BadRequest("User object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                var dbTask = _repository.Task.GetTaskById(id);

                if (dbTask.IsEmptyObject())
                {
                    return(NotFound());
                }

                task.Id = id;
                _repository.Task.UpdateTask(dbTask, task);
                _repository.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Something went wrong inside UpdateTask action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Exemplo n.º 2
0
        public IActionResult CreateTask([FromBody] Entities.Models.Task task)
        {
            try
            {
                if (task == null)
                {
                    return(BadRequest("User object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }
                _repository.Task.CreateTask(task);
                return(CreatedAtRoute("TaskById", new { id = task.Id }, task));
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Something went wrong inside CreateTask action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }