private void button1_Click(object sender, EventArgs e) { Adduser add = new Adduser(); add.ShowDialog(); load(); }
public ActionResult DeleteConfirmed(int id) { Adduser adduser = db.Adduser.Find(id); db.Adduser.Remove(adduser); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "uid,Name,Location")] Adduser adduser) { if (ModelState.IsValid) { db.Entry(adduser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(adduser)); }
public ActionResult Create([Bind(Include = "uid,Name,Location")] Adduser adduser) { if (ModelState.IsValid) { db.Adduser.Add(adduser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(adduser)); }
// GET: Addusers/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Adduser adduser = db.Adduser.Find(id); if (adduser == null) { return(HttpNotFound()); } return(View(adduser)); }
public int AddUser(Adduser user) { if (user.Username == "") { return(-2); } if (user.Username == _adminUsername) { return(-3); } using (var connection = new SqlConnection(_connectionString)) { try { user.Password = SHA.ComputeSHA256Hash(user.Password); var parameter = new { username = user.Username, password = user.Password, firstname = user.FirstName, lastname = user.LastName }; var sql = "INSERT INTO Users (username, password, firstname, lastname) VALUES (@username, @password, @firstname, @lastname)"; connection.Execute(sql, parameter); // If this fails then the user will still be added with no permissions var GetUserId = "SELECT Id FROM Users WHERE Username = @username"; var UserId = connection.QuerySingle <int>(GetUserId, parameter); for (int i = 0; i < user.PermissionsArray.Length; i++) { var parameterPermId = new { PermissionId = user.PermissionsArray[i] }; var GetPermissionId = "SELECT Id FROM Permissions WHERE PermissionId = @PermissionId"; var PermId = connection.QuerySingle <int>(GetPermissionId, parameterPermId); var parameter2 = new { UserId, PermissionId = PermId }; var sql2 = "INSERT INTO UsersPermissions (UserId, PermissionId) VALUES (@UserId, @PermissionId)"; connection.Execute(sql2, parameter2); } return(1); } catch { return(-1); } } }
public int AddUser([FromBody] Adduser user) { return(_userService.AddUser(user)); }