コード例 #1
0
 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;
 }
コード例 #2
0
 public UserResponse(int userID, tbl_User user)
 {
     this.userID = userID;
     this.username = user.username;
     this.password = user.password;
     this.emailAddress = user.emailAddress;
 }
コード例 #3
0
 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();
 }
コード例 #4
0
 public int Add(tbl_User entity)
 {
     if (!_collection.Contains(entity))
     {
         this._collection.Add(entity);
         return this._collection.Count;
     }
     return 0;
 }
コード例 #5
0
 public void InsertEntity(tbl_User user)
 {
     this._context.tbl_User.Add(user);
     this.Commit();
 }