public async Task <IActionResult> PutUsers(int id, Users users) { if (id != users.Id) { return(BadRequest()); } _context.Entry(users).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutServices(int id, Services services) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != services.ServiceID) { return(BadRequest()); } db.Entry(services).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServicesExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual async Task <TEntity> AddAsyn(TEntity t) { Context.Set <TEntity>().Add(t); await Context.SaveChangesAsync(); return(t); }
public async Task <AccessToken> Create(Guid userId) { var encryptor = new System.Security.Cryptography.Rfc2898DeriveBytes(Guid.NewGuid().ToString(), Guid.NewGuid().ToByteArray()); var value = Convert.ToBase64String(encryptor.GetBytes(500)); var token = new Token(value, userId); await db.Tokens.AddAsync(token); await db.SaveChangesAsync(); return(ToAccessToken(token)); }
public async Task <ActionResult <Users> > ValidateUser(int id) { var users = await _context.Users.FindAsync(id); if (users == null) { l.LogAction("User validation failed. (id=" + id + ")"); return(NotFound()); } else { users.IsVerified = true; try { await _context.SaveChangesAsync(); l.LogAction("User validation success! (id=" + id + ")"); } catch (DbUpdateConcurrencyException) { if (!UsersExists(id)) { l.LogAction("User validation failed. (id=" + id + ")"); return(NotFound()); } else { l.LogAction("User validation failed. (id=" + id + ")"); throw; } } } return(users); }
public async Task SaveChangesAsync() { await _context.SaveChangesAsync(); }