public static int Delete_UserSys(int id) { dbRegistrationContext context1 = new dbRegistrationContext(); try { using (TransactionScope scope = new TransactionScope()) { USERSYS us = new USERSYS() { ID = id }; context1.USERSYS.Attach(us); context1.USERSYS.Remove(us); try { context1.SaveChanges(); scope.Complete(); return(1); } catch (Exception) { return(-1); } } } catch (Exception) { return(-1); } }
public static int Insert_UserSys(string username, string userpass) { dbRegistrationContext context1 = new dbRegistrationContext(); try { using (TransactionScope scope = new TransactionScope()) { int id = 0; try { id = context1.USERSYS.Max(p => p.ID + 1); } catch (Exception) { id = 1; } var sha512 = new SHA512Managed(); var bytes = UTF8Encoding.UTF8.GetBytes(userpass); var hash = sha512.ComputeHash(bytes); var pass = Encoding.UTF8.GetString(hash); USERSYS usu = new USERSYS() { ID = id, USERNAME = username, USERPASS = pass }; context1.USERSYS.Add(usu); try { context1.SaveChanges(); scope.Complete(); return(1); } catch (Exception) { return(-1); } } } catch (Exception) { return(-1); } }