Exemple #1
0
        public T Create(T entity)
        {
            var newEntity = _db.Set <T>().Add(entity);

            _db.SaveChanges();
            return(newEntity.Entity);
        }
Exemple #2
0
        public async Task <AuthenticateResponse> RefreshToken(string refreshToken)
        {
            var user = db.ApplicationUser.SingleOrDefault(u => u.RefreshTokens.Any(t => t.Token == refreshToken));

            // return null if no user found with token
            if (user == null)
            {
                return(null);
            }

            var userRefreshToken = user.RefreshTokens.Single(x => x.Token == refreshToken);

            // return null if token is no longer active
            if (!userRefreshToken.IsActive)
            {
                return(null);
            }

            // replace old refresh token with a new one and save
            var newRefreshToken = tokenService.GenerateRefreshToken();

            userRefreshToken.Revoked         = DateTime.UtcNow;
            userRefreshToken.ReplacedByToken = newRefreshToken.Token;
            user.RefreshTokens.Add(newRefreshToken);
            db.Update(user);
            db.SaveChanges();

            // generate new jwt
            var jwtToken = await tokenService.GenerateJwtToken(user);

            return(new AuthenticateResponse(user, jwtToken, newRefreshToken.Token));
        }
Exemple #3
0
        public IActionResult Create(Quote thing)
        {
            _context.quotes.Add(thing);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public IActionResult Contact(Quotes model)
        {
            //ViewData["Message"] = "Your contact page.";
            if (ModelState.IsValid)
            {
                _context.Add(model);
                _context.SaveChanges();
                var quotes = _context.Quotes.ToList();
                return(View("Index", quotes));
            }

            return(View(model));
        }
Exemple #5
0
        public IActionResult Create([FromBody] Quotes quote)
        {
            if (quote == null)
            {
                return(BadRequest());
            }


            _context.Add(quote);
            _context.SaveChanges();

            return(CreatedAtRoute("GetQuotes", new { id = quote.Id }, quote));
        }
Exemple #6
0
        public IActionResult Delete(long id)
        {
            var quote = new QuotesContext().Quotes.FirstOrDefault(x => x.Id == id);

            if (quote == null)
            {
                return(NotFound());
            }
            var context = new QuotesContext();

            context.Remove(quote);
            context.SaveChanges();
            return(new NoContentResult());
        }
Exemple #7
0
 public IActionResult SaveQuote(string text, string author = "Desconocido")
 {
     try
     {
         //if (q.Quotes is null) q.Quotes = new List<Quote>();
         q.Quotes.Add(new Quote {
             Text = text, Author = author, TimeStamp = DateTime.Now
         });
         q.SaveChanges();
         return(new OkResult());
     }
     catch (Exception ex)
     {
         return(new StatusCodeResult(503));
     }
 }
Exemple #8
0
        public IActionResult Update(long id, [FromBody] Quotes item)
        {
            if (item == null || item.Id != id)
            {
                return(BadRequest());
            }

            var context = new QuotesContext();

            var quote = context.Quotes.FirstOrDefault(t => t.Id == id);

            if (quote == null)
            {
                return(NotFound());
            }

            quote.Credit = item.Credit;
            quote.Quote  = item.Quote;

            context.Quotes.Update(quote);
            context.SaveChanges();
            return(new NoContentResult());
        }