コード例 #1
0
ファイル: AuthController.cs プロジェクト: nardo7/ApiConnector
        public async Task <IActionResult> PutCode(int id, Code code)
        {
            if (id != code.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public IEnumerable <string> Get(string code, string state)
        {
            _logger.LogInformation("from get receiving a code");
            if (code == null)
            {
                _logger.LogInformation("code was null");
            }
            else
            {
                using (StreamWriter writer = new StreamWriter("./code"))
                {
                    writer.WriteLine(code);
                    _logger.LogInformation("code stored in txt, done!");
                    writer.Close();
                }
                using (var context = new CodesContext())
                {
                    var result = context.Codes.AsNoTracking().FirstOrDefault(x => x.secret_key == state);
                    if (result == null)
                    {
                        _logger.LogInformation("there is not auth for this code request yet, or invalid state");
                    }
                    else
                    {
                        result.code = code;
                        context.Entry(result).State = EntityState.Modified;

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!context.Codes.Any(e => e.Id == result.Id))
                            {
                                return(new string[] { "NOT FOUND" });
                            }
                        }
                    }
                }
            }
            return(new string[] { });
        }