public async Task <IHttpActionResult> GetTAB_Users(int id) { TAB_Users u = await db.TAB_Users.FindAsync(id); if (u == null) { return(NotFound()); } var reponse = new UserModel(); reponse.ID_User = u.ID_User; reponse.UserFirstname = u.UserFirstname; reponse.UserSurname = u.UserSurname; reponse.UserLogin = u.UserLogin; reponse.CreationDate = u.CreationDate; return(Ok(reponse)); }
public async Task <IHttpActionResult> PutTAB_Users(int id, string firstName, string surName) { /* * * if (id != tAB_Users.ID_User) * { * return BadRequest(); * }*/ TAB_Users u = await db.TAB_Users.FindAsync(id); if (u == null) { return(NotFound()); } u.UserFirstname = firstName; u.UserSurname = surName; db.Entry(u).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TAB_UsersExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> DeleteTAB_Users(int id) { TAB_Users tAB_Users = await db.TAB_Users.FindAsync(id); if (tAB_Users == null) { return(NotFound()); } db.TAB_Users.Remove(tAB_Users); UserModel user = new UserModel(); user.ID_User = user.ID_User; user.UserFirstname = user.UserFirstname; user.UserSurname = user.UserSurname; user.UserLogin = user.UserLogin; user.CreationDate = user.CreationDate; await db.SaveChangesAsync(); return(Ok(tAB_Users)); }
public int PostTAB_Users(string firstName, string surName, string login) { var users = db.TAB_Users.Where(u => u.UserLogin == login).ToList(); if (users.Count() > 0) { return(0); } TAB_Users user = new TAB_Users() { UserFirstname = firstName, UserSurname = surName, UserLogin = login, CreationDate = DateTime.Now }; int res = db.TAB_Users.Add(user).ID_User; db.SaveChangesAsync(); //return CreatedAtRoute("DefaultApi", new { id = tAB_Users.ID_User }, tAB_Users); return(res); }