コード例 #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 ResponseAttribute IsEmailExist(string emailAddress)
 {
     ResponseAttribute response = new ResponseAttribute();
     using (IChatRepository repo = new Repository(new ChatDbContext()))
     {
         response.Response = true;
         try
         {
             tbl_User user = repo.GetEntity(emailAddress);
             if (user != null)
                 response.Response = true;
             else
                 response.Response = false;
         }
         catch (Exception ex) {
             response.Response = false;
             response.Message = ex.Message;
         }
     }
     return response;
 }