public async Task HandleAsync(UserCreated @event) { await _usersService.AddAsync(new User { Id = @event.UserId, Name = @event.Name }); }
//private void GetRecommendedBookStores() //{ // //var recommendations = _bookStoreService.GetBookStoresAssignedToUsers(); // //foreach(var recommendation in recommendations) // //{ // // Console.WriteLine($"{recommendation.Login} {recommendation.City} {recommendation.BookStoreName}"); // //} //} private void AddUser() { var newUser = new User { Login = _ioHelper.GetTextFromUser("Login"), Password = _ioHelper.GetTextFromUser("Password"), PhoneNumber = _ioHelper.GetTextFromUser("Phone number with country prefix"), City = _ioHelper.GetTextFromUser("City") }; _usersService.AddAsync(newUser).Wait(); Console.WriteLine("User added successfully"); }
public async Task <IActionResult> Add([FromBody] NewUserRequest userRequest) { var userResult = await usersService.AddAsync(userRequest.Email, userRequest.Password); if (userResult.Errors != null && userResult.Errors.Any()) { return(BadRequest(new AuthFailedResponse { Errors = userResult.Errors })); } return(Ok(new AuthSuccessResponse { Token = userResult.Token })); }
public async Task <IHttpActionResult> AddUsersAdmin([FromBody] AddUsersRequest request) { try { if (ModelState.IsValid) { await _service.AddAsync(request); await _service.CommitAsync(); return(Ok()); } return(BadRequest(ModelState)); } catch (Exception ex) { await _service.RollbackAsync(); return(BadRequest(GetError(ex))); } }
public async Task <IActionResult> Add([FromBody] UserRequest userRequest) { await usersService.AddAsync(userRequest.Email, userRequest.Password); return(NoContent()); }
public async Task <ActionResult <int> > Post([FromBody] UsersDto dto) { return(await _usersService.AddAsync(dto)); }
public virtual async Task <ActionResult> Editor(UserModel model, bool?saveAndContinue) { model.CountriesList = await _countriesService.GetAsSelectListAsync(); model.UserGroupsList = await _userGroupsService.GetAsSelectListAsync(); if (!ModelState.IsValid) { return(View(model)); } var record = _userModelFactory.PrepareTblUsers(model); var recordId = record.Id; try { if (model.Avatar != null) { if (record.Id != null) { var olduser = await UserManager.FindByIdAsync(record.Id); try { var oldAvatarFile = Server.MapPath(olduser.Avatar); if (System.IO.File.Exists(oldAvatarFile)) { System.IO.File.Delete(oldAvatarFile); } } catch { } } record.Avatar = model.Avatar.SaveToAppData(); } if (model.Id == null) { //Add new record if (string.IsNullOrWhiteSpace(model.Password)) { ModelState.AddModelError("Password", _localizationService.GetResource("PasswordCannotEmpty")); return(View(model)); } record.RegisterDate = DateTime.Now; recordId = await _usersService.AddAsync(record, model.Password); } else { //Edit record var oldUser = await UserManager.FindByIdAsync(model.Id); record.RegisterDate = oldUser.RegisterDate; record.UserLastLoginDate = oldUser.UserLastLoginDate; record.UserLatestIP = oldUser.UserLatestIP; if (model.Avatar == null) { record.Avatar = oldUser.Avatar; } await _usersService.UpdateAsync(record, model.Password); } await _usersService.SetUserRoleAsync(recordId, model.IsAdmin); } catch (Exception e) { var errorCode = ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Error(e, System.Web.HttpContext.Current)); ModelState.AddModelError("", string.Format(_localizationService.GetResource("ErrorOnOperation"), e.Message, errorCode)); return(View(model)); } if (saveAndContinue != null && saveAndContinue.Value) { return(RedirectToAction("Editor", "ManageUsers", new { id = recordId })); } return(Content(@"<script language='javascript' type='text/javascript'> window.close(); window.opener.refreshUsersGrid(); </script>")); }
public async Task <IActionResult> AddUserAsync([FromBody] User user) { BaseResponse result = await _usersService.AddAsync(user); return(Ok(result)); }
public async Task <IActionResult> Add([FromBody] UserModel model) { var newModel = await _service.AddAsync(model); return(CreatedAtRoute("GetUserById", new { id = newModel.Id }, newModel)); }