예제 #1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] TUserTasks task)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != task.Id)
            {
                return(BadRequest());
            }
            try
            {
                await _userTasksRepository.Update(task);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!await _userTasksRepository.Exist(Convert.ToInt32(task.Id)))
                {
                    return(NotFound());
                }
                else
                {
                    log.WriteLog(ex.ToString(), "UserTasksController.txt");
                    return(BadRequest());
                }
            }

            return(Ok(task));
        }
예제 #2
0
        public async Task <TUserTasks> Update(TUserTasks task)
        {
            try
            {
                _unitofWork.UserTasksRepository.Update(task);
                await _unitofWork.Save();

                return(task);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                log.WriteLog(ex.ToString(), "UserTasksRepository.txt");
                return(null);
            }
        }
예제 #3
0
        public async Task <IActionResult> Post([FromBody] TUserTasks user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _userTasksRepository.Add(user);

                return(Ok());
            }
            catch (DbUpdateConcurrencyException ex)
            {
                log.WriteLog(ex.ToString(), "UserTasksController.txt");
                return(BadRequest());
            }
        }