[HttpPost]// POST: api/Users public async Task <IActionResult> PostUser([FromBody] ViewModels.UserRegistration user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Models.User createdUser = await _userService.CreateUser(user); return(Ok(new ViewModels.User() { ID = createdUser.ID, Login = createdUser.Login, Email = createdUser.Email })); }
public async Task <Models.User> CreateUser(ViewModels.UserRegistration user) { Models.User creatingUser = new Models.User { Login = user.Login, Email = user.Email }; creatingUser.Password = new PasswordHasher <Models.User>().HashPassword(creatingUser, user.Password); EntityEntry <Models.User> createdUser = await _context.Users.AddAsync(creatingUser); await _context.SaveChangesAsync(); return(createdUser.Entity); }
private async Task <Models.User> AddUser(ViewModels.UserRegistration view) { var data = _appDbContext.UserInfos.Include(k => k.User).Any(o => o.User.Username == view.Email && o.TokenIsCompleted != true); //var data2 = _appDbContext.Profiles.Include(m ) var userDetails = await _appDbContext.Users.Where(x => x.Username == view.Email).FirstOrDefaultAsync(); if (data) { //userDetails.Id = userDetails.Id; userDetails.OrganizationId = 1; userDetails.Username = view.Email; userDetails.CreatedBy = "Anonymous User"; userDetails.ModifiedBy = "Anonymous User"; userDetails.Created = System.DateTime.UtcNow; userDetails.Modified = System.DateTime.UtcNow; userDetails.IsOnline = false; userDetails.IsAnonymous = false; userDetails.PermissionSid = ""; userDetails.PermissionSetSid = "2"; userDetails.LastUsedPermissionSetId = 2; userDetails.IsTC_Accepted = true; await _appDbContext.SaveChangesAsync(); return(userDetails); } var user = new Models.User { OrganizationId = 1, Username = view.Email, CreatedBy = "Anonymous User", ModifiedBy = "Anonymous User", Created = System.DateTime.UtcNow, Modified = System.DateTime.UtcNow, IsOnline = false, IsAnonymous = false, PermissionSid = "", PermissionSetSid = "2", LastUsedPermissionSetId = 2, IsTC_Accepted = true }; if (view.FirstName.IsArabicString()) { user.NameAr = $"{view.FirstName} {view.LastName}"; user.LanguageKey = "ar"; } else { user.NameEn = $"{view.FirstName} {view.LastName}"; user.LanguageKey = "en"; } _appDbContext.Users.Add(user); await _appDbContext.SaveChangesAsync(); return(user); }
public AccountResponse(ViewModels.UserRegistration user, Exception e) : this(true, string.Empty, user) { }