public IActionResult Post([FromBody] UserRegisterRequestViewModel inputModel) { try { if (!ModelState.IsValid) { return(BadRequest(new ApiBadRequestResponse(ModelState))); } var currentUser = HttpContext.User; if (currentUser.HasClaim(c => c.Type == ClaimTypes.Email)) { string email = currentUser.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value; inputModel.createdby = email; } ResponseViewModel <UserRegisterResponseViewModel> response = userService.CreateUser(inputModel); if (response.Status) { return(Ok(new ApiOkResponse((int)HttpStatusCode.OK, true, response.Message, response.Result))); } else { return(Ok(new ApiBadResponse(response.StatusCode, response.Status, response.Message, "", response.Errors))); } } catch (Exception ex) { if (ex.InnerException != null) { loggerService.LogError(1, "## [UserController][POST] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { loggerService.LogError(1, "## [UserController][POST] innerexception message :" + ex.InnerException.Message.ToString()); } } else { loggerService.LogError(1, "## [UserController][POST] exception :" + ex.Message.ToString()); } var Message = errorMessageService.GetErrorMessagesData("501"); return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiInternalServerErrorResponse((int)HttpStatusCode.InternalServerError, false, Message, ""))); } }
public UserRegisterResponseViewModel Register(UserRegisterRequestViewModel user) { User _user = mapper.Map <User>(user); if (this.userRepository.Find(x => x.Email == _user.Email & !x.IsDeleted) != null) { return new UserRegisterResponseViewModel { IsSuccessfulRegistration = false, Errors = new List <string> { "Já existe usuário cadastrado para esse email" } } } ; _user.DateCreated = DateTime.Now; try { this.userRoleRepository.Create(new UserRole { Id = Guid.NewGuid(), DateCreated = DateTime.Now, IsDeleted = false, UserId = userRepository.Create(_user).Id, RoleId = roleRepository.Find(x => x.Name == "User" & !x.IsDeleted).Id });; return(new UserRegisterResponseViewModel { IsSuccessfulRegistration = true }); } catch (Exception e) { return(new UserRegisterResponseViewModel { IsSuccessfulRegistration = false, Errors = new List <string> { e.Message } }); } }
public async Task <InpowerResult> Registration(UserRegisterRequestViewModel model, string url) { InpowerResult resp = null; try { resp = await _helper.Post <UserRegisterRequestViewModel>(model, url); return(resp); } catch (Exception ex) { CrashReportService crashReport = new CrashReportService(); CrashReportModel CR = new CrashReportModel(); CR.Filename = "Registration"; CR.Eventname = "AccountService"; // CR.UserID = GlobalClass.UserID == null ? "0" : GlobalClass.UserID; CR.ErrorMsg = ex.Message + ex.StackTrace; await crashReport.SendCrashReport(CR, GlobalConstant.CrashUrl); return(resp); } }
public ResponseViewModel <UserRegisterResponseViewModel> CreateUser(UserRegisterRequestViewModel inputModel) { ResponseViewModel <UserRegisterResponseViewModel> response = new ResponseViewModel <UserRegisterResponseViewModel>(); List <Error> lstError = new List <Error>(); UserRegisterResponseViewModel objUserResponseViewModel = new UserRegisterResponseViewModel(); try { _loggerService.LogInformation(1, "## [UserService][CreateUser]- Start CreateUser user method."); var finduser = _userRepository.FindByEmail(inputModel.email); if (finduser == null) { byte[] passwordHash, passwordSalt; _securityHelper.CreatePasswordHash(inputModel.password, out passwordHash, out passwordSalt); Users objuser = new Users() { Address = inputModel.address, BirthDate = DateTimeOffset.Parse(inputModel.birthdate).UtcDateTime, ContactNumber = inputModel.contactnumber, Email = inputModel.email, FirstName = inputModel.firstname, LastName = inputModel.lastname, Status = inputModel.status, UserType = inputModel.usertype, PasswordHash = passwordHash, PasswordSalt = passwordSalt, CreatedBy = inputModel.createdby, UpdatedBy = inputModel.createdby, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; _loggerService.LogInformation(1, "## [UserService][CreateUser]- Create User Model Email : " + objuser.Email + " , FirstName : " + objuser.FirstName + " , LastName : " + objuser.LastName); var userId = _userRepository.Add(objuser); if (userId > 0) { string birthDate = Convert.ToString(inputModel.birthdate); objUserResponseViewModel = new UserRegisterResponseViewModel() { userid = userId, address = inputModel.address, birthdate = string.Format("{0:yyyy-MM-ddTHH:mm:ssZ}", birthDate), contactnumber = inputModel.contactnumber, email = inputModel.email, firstname = inputModel.firstname, lastname = inputModel.lastname, status = inputModel.status, usertype = inputModel.usertype }; _loggerService.LogInformation(1, "## [UserService][CreateUser]- User created sucessfully : " + objUserResponseViewModel.email); } else { _loggerService.LogInformation(1, "## [UserService][CreateUser]- User not created in userRepository for email id : " + inputModel.email); var errorMessage = _errorMessageService.GetErrorMessagesData("2020"); var objError = new Error { Code = "2020", Message = errorMessage }; lstError.Add(objError); } } else { _loggerService.LogInformation(1, "## [UserService]-[CreateUser]- User already exists "); var errorMessage = _errorMessageService.GetErrorMessagesData("2020"); errorMessage = errorMessage.Replace("$$InputData$$", "User"); var objError = new Error { Code = "2020", Message = errorMessage }; lstError.Add(objError); } if (lstError.Count == 0) { response.Status = true; response.Message = "User Created Sucessfully"; response.StatusCode = (int)HttpStatusCode.OK; response.Result = objUserResponseViewModel; } else { response.Status = false; response.Errors = lstError; response.StatusCode = (int)HttpStatusCode.BadRequest; } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [UserService][CreateUser] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [UserService][CreateUser] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [UserService][CreateUser] exception :" + ex.Message.ToString()); } response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("501"); response.StatusCode = (int)HttpStatusCode.BadRequest; return(response); } return(response); }