/// <summary> /// Register new user /// </summary> /// <returns>new user Id</returns> public int SignUp(UserModel userModel) { int userId = 0; using (HandshakerEntities handshakerEntityContainer = new HandshakerEntities()) { if (handshakerEntityContainer.UserSet.Count(u => u.Username.Equals(userModel.Username)) > 0) throw new Exception("Sistemde " + userModel.Username + " adıyla bir kullanıcı bulunmaktadır"); #region hash password byte[] passwordAsByte = System.Text.Encoding.ASCII.GetBytes(userModel.Password); passwordAsByte = new System.Security.Cryptography.SHA256Managed().ComputeHash(passwordAsByte); String hashedPassword = System.Text.Encoding.ASCII.GetString(passwordAsByte); #endregion User newUser = new User() { FirstName = userModel.FirstName, LastName = userModel.LastName, Username = userModel.Username, Email = userModel.Email, Password = hashedPassword }; handshakerEntityContainer.UserSet.AddObject(newUser); handshakerEntityContainer.SaveChanges(); userId = newUser.Id; } return userId; }
/// <summary> /// Deprecated Method for adding a new object to the UserSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUserSet(User user) { base.AddObject("UserSet", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="username">Initial value of the Username property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="password">Initial value of the Password property.</param> public static User CreateUser(global::System.Int32 id, global::System.String firstName, global::System.String lastName, global::System.String username, global::System.String email, global::System.String password) { User user = new User(); user.Id = id; user.FirstName = firstName; user.LastName = lastName; user.Username = username; user.Email = email; user.Password = password; return user; }