コード例 #1
0
 public User InsertUser(User user)
 {
     //return _repository.FindSingle();
     //User user = new User { Id = "111",UserName="******",Birthday=DateTime.Now};
     //User user = _repository.FindSingle();
     _repository.Add(user, "User");
     return(user);
 }
コード例 #2
0
 public async Task InvokeAsync(HttpContext httpContext)
 {
     try
     {
         await _next(httpContext);
     }
     catch (Exception ex)
     {
         Error error = new Error();
         error.Message    = ex.Message;
         error.StackTrace = ex.StackTrace;
         error.UserId     = httpContext.User.Identity.Name;
         await _errorRepository.Add(error);
         await HandleExceptionAsync(httpContext, ex);
     }
 }
コード例 #3
0
 public async Task<ResponseViewModel> RegisterUser(UserDto model)
 {
     ResponseViewModel response = new ResponseViewModel();
     try
     {
         var user = _mapper.Map<User>(model);
         var existingUser = GetSingleByUsernameorEmail(user.Email);
         if (!existingUser)
         {
             if (model.Password != null)
             {
                 byte[] passwordHash, passwordSalt;
                 CreatePasswordHash(model.Password, out passwordHash, out passwordSalt);
                 user.HashedPassword = passwordHash; user.Salt = passwordSalt;
                 var result = await _userRepository.Add(user);
                 if (result != null)
                 {
                     model.Id = result.Id; model.CreatedDate = result.CreatedDate; model.ModifiedDate = result.ModifiedDate;
                     model.Password = null;
                     response.Message = "Registration successful";
                     response.ResponseData = model;
                     response.Status = (int)Numbers.One;
                 }
                 else
                 {
                     response.Message = Constants.Error;
                     response.Status = (int)Numbers.Zero;
                 }
             }
             else
             {
                 response.Message = "Password is required";
                 response.Status = (int)Numbers.Zero;
             }
         }
         else
         {
             response.Message = "User already registered with email id provided";
             response.Status = (int)Numbers.Zero;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return response;
 }