public UserResponse CreateUser(string username, string password, string emailAddress) { UserResponse response = new UserResponse(); using (IChatRepository repo = new Repository(new ChatDbContext())) { try { tbl_User user = repo.GetEntity(emailAddress); if (user == (tbl_User)null) { response.Response = ResponseState.Ok.ToString(); string salt = Guid.NewGuid().ToString().Replace("-", ""); password = ChatUtility.ChatUtility.EncryptPassword(password, salt); user = new tbl_User { Username = username, Password = password, Salt = salt, EmailAddress = emailAddress, CreateDate = DateTime.UtcNow }; repo.InsertEntity(user); response.ToUserResponse(user); } else throw new InvalidOperationException("Account already exists."); } catch (Exception ex) { response.Response = ResponseState.NotOK.ToString(); response.Message = ex.Message; } } return response; }
public UserResponse(int userID, tbl_User user) { this.userID = userID; this.username = user.username; this.password = user.password; this.emailAddress = user.emailAddress; }
public void ToUserResponse(tbl_User user) { this.userID = user.UserID; this.username = user.Username; this.password = user.Password; this.emailAddress = user.EmailAddress; this.createDate = user.CreateDate.ToString(); }
public int Add(tbl_User entity) { if (!_collection.Contains(entity)) { this._collection.Add(entity); return this._collection.Count; } return 0; }
public void InsertEntity(tbl_User user) { this._context.tbl_User.Add(user); this.Commit(); }