コード例 #1
0
ファイル: UserDAO.cs プロジェクト: becek2n/netcore-todo
        public async Task <ResultModel <object> > SaveToken(TokenRefreshDTO model)
        {
            ResultModel <object> result = new ResultModel <object>();

            try
            {
                using (var transaction = _context.Database.BeginTransaction()) {
                    try
                    {
                        var token = _mapper.Map <TokenRefreshDTO, TokenRefresh>(model);

                        await _context.TokenRefreshes.AddAsync(token);

                        await _context.SaveChangesAsync();

                        transaction.Commit();

                        result.SetSuccess("success");
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                result.SetFailed(ex.Message);
                _logging.WriteErr(ex);
            }

            return(result);
        }
コード例 #2
0
        public async Task <IActionResult> PutTask(int id, dataLayer.Task task)
        {
            if (id != task.TaskId)
            {
                return(BadRequest());
            }

            _context.Entry(task).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }