コード例 #1
0
        /// <summary> Delete task </summary>
        public async Task <ActionResult> DeleteTaskAsync(int id)
        {
            var result = await _taskRepository.DeleteByIdAsync(id);

            if (!result)
            {
                return(new NotFoundObjectResult($"Task is not found with id:{id}"));
            }

            return(new OkResult());
        }
コード例 #2
0
        public async Task <ActionResult <Models.Task> > DeleteTask(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(BadRequest(new Helpers.ResponseApiHelper().Error("Id is required")));
                }
                var task = await _repo.GetByIdAsync(id);

                if (task == null)
                {
                    return(NotFound(new Helpers.ResponseApiHelper().Error(404, "The task does not exist")));
                }
                await _repo.DeleteByIdAsync(id);

                return(Ok(new Helpers.ResponseApiHelper().Success("Task deleted")));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new Helpers.ResponseApiHelper().Error(500, ex.Message)));
            }
        }