示例#1
0
        public async Task <ActionResult <TaskDetailsModel> > Post(TaskDetailsModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var task = await _taskRepository.GetTaskAsync(model.TaskId.GetValueOrDefault());

                if (task == null)
                {
                    return(NotFound("Task not Found"));
                }



                var taskDetails = _mapper.Map <Test.Core.TaskDetails>(model);
                _repository.Add(taskDetails);
                if (await _repository.SaveChangesAsync() == 1)
                {
                    return(Created($"/api/taskdetails/{taskDetails.Id}", _mapper.Map <TaskDetailsModel>(taskDetails)));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(BadRequest());
        }
示例#2
0
        public async Task <ActionResult <TaskModel> > Get(int id)
        {
            try
            {
                var result = await _repository.GetTaskAsync(id);

                if (result == null)
                {
                    return(NotFound());
                }
                TaskModel model = _mapper.Map <TaskModel>(result);
                return(model);
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError));
            }
        }