public IHttpActionResult PutUserTable(int id, UserTable userTable) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userTable.UserId) { return(BadRequest()); } userDb.Entry(userTable).State = EntityState.Modified; try { UserCrypt crypt = new UserCrypt(); userTable.UserPass = crypt.EncryptPass(userTable.UserPass); userDb.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserTableExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// Check the user is valid : api/LoginAuth public HttpResponseMessage Post([FromBody] UserCred user) { try { UserCrypt crypt = new UserCrypt(); string encryptPass = crypt.EncryptPass(user.UserPass); UserTable foundUser = userDb.UserTables.SingleOrDefault(x => x.UserEmail == user.UserEmail && x.UserPass.Equals(encryptPass)); if (foundUser != null) { foundUser.UserPass = crypt.DecryptPass(foundUser.UserPass); return(Request.CreateResponse(HttpStatusCode.OK, foundUser)); } else { return(Request.CreateResponse(HttpStatusCode.OK, foundUser)); } } catch (ArgumentException e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message)); /*return Request.CreateResponse(HttpStatusCode.BadRequest, "Something went wrong");*/ } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message)); } finally { } }
public IQueryable <UserTable> GetUserTables() { UserCrypt crypt = new UserCrypt(); foreach (UserTable app in userDb.UserTables) { app.UserPass = crypt.DecryptPass(app.UserPass); } return(userDb.UserTables); }
public IHttpActionResult PostUserTable(UserTable userTable) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } UserCrypt crypt = new UserCrypt(); userTable.UserPass = crypt.EncryptPass(userTable.UserPass); userDb.UserTables.Add(userTable); userDb.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = userTable.UserId }, userTable)); }