public static void UpdateUser(string login, string newLogin, string name, string surname, string password) { var db = new SQLtoLinqDataContext(ConnString); var result = (from u in db.Users where u.login == login select u).Single(); if (newLogin != null) { result.login = newLogin; } if (name != null) { result.name = name; } if (surname != null) { result.surname = surname; } if (password != null) { result.password = UserCtx.Encrypt(password); } db.SubmitChanges(); }
public static void AddUser(string login, string password, string name, string surname) { var db = new SQLtoLinqDataContext(ConnString); var user = new User(); var result = (from u in db.Users where login == u.login select u).SingleOrDefault(); if (result != null) { throw new Exception("User already exists"); } user.login = login; user.password = UserCtx.Encrypt(password); user.name = name; user.surname = surname; db.Users.InsertOnSubmit(user); db.SubmitChanges(); }