//można i tak ale lepiej oddzielnie dla przejżystości //[Route("{id:int}")] //[AcceptVerbs("GET","HEAD")] //public IHttpActionResult Head(int id) //{ // var user = userService.Get(id); // if (user == null) // return NotFound(); // if (this.Request.Method == HttpMethod.Get) // return Ok(user); // return Ok(); //} public IHttpActionResult Post(User user) { userService.Add(user); //return Created($"http://localhost:50302/api/users/{user.Id}", user); return(CreatedAtRoute("DefaultApi", new { id = user.Id }, user)); //on error BadRequest(); }
public async Task <IActionResult> Add(UserRequest userRequest) { var newUser = _mapper.Map <User>(userRequest); await _usersService.Add(newUser); return(NoContent()); }
public async Task <IActionResult> Add([FromBody] UserDto user) { var userMapped = _mapper.Map <UserDao>(user); await _usersService.Add(userMapped); return(Ok()); }
public ActionResult Create(Users user) { try { if (!ModelState.IsValid) { var userTypesList = _userTypesService.GetAll(); var model = new UsersVM { User = new Users(), UserTypes = userTypesList }; } user.CreationDate = DateTime.Now; _usersService.Add(user); TempData.Add("message", "Kullanıcı başarıyla eklendi."); return(RedirectToAction("index")); } catch (Exception ex) { TempData.Add("message", "Kullanıcı oluştururken hata ile karşılaştı. Hata: " + ex.Message); return(View()); } }
public IActionResult Post(Users user) { var result = _usersService.Add(user); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Add(User users) { var result = _usersService.Add(users); if (result.Success) { return(Ok(result)); } return(BadRequest(result.Message)); }
public IAjaxResult AddUser(Users users) { if (_usersService.Add(users)) { return(Success("添加成功")); } else { return(Error("添加失败")); } }
public ActionResult AddUsuario(Users users) { try { _usersService.Add(users); return(Ok()); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> AddPost(int userId, NewPostDto newPostDto) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var user = await usersService.GetUser(userId); newPostDto.BlogId = user.Blog.Id; var post = mapper.Map <Post>(newPostDto); usersService.Add <Post>(post); if (await usersService.SaveAll()) { return(Ok()); } return(BadRequest("Failed to add post")); }
public int Register(GetLoginDto getLoginDto) { Users user = new Users() { Name = getLoginDto.Name, Pwd = getLoginDto.Pwd, Email = getLoginDto.Email, RoleId = getLoginDto.RoleId }; if (_usersService.Find(c => c.Name == user.Name) != null) { return(2); } return(_usersService.Add(user) ? 0 : 1); }
public IDataResult <User> Register(UsersForRegisterDto userForRegisterDto, string password) { byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); var user = new User { Email = userForRegisterDto.Email, FirstName = userForRegisterDto.FirstName, LastName = userForRegisterDto.LastName, PasswordHash = passwordHash, PasswordSalt = passwordSalt, }; _userService.Add(user); return(new SuccessDataResult <User>(user, "Kayıt oldu")); }
public IDataResult <Users> Register(UserForRegisterDto userForRegisterDto, string password) { byte[] passwordHash, passwordSalt; HashingHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); var user = new Users { Email = userForRegisterDto.Email, FirstName = userForRegisterDto.FirstName, LastName = userForRegisterDto.LastName, PasswordHash = passwordHash, PasswordSalt = passwordSalt, Status = true }; _userService.Add(user); return(new SuccessDataResult <Users>(user, Messages.UserRegistered)); }
public IActionResult GetCarpetPitches() { var user = new User() { FirstName = "gg" }; { _usersService.Add(user); }; var model = new userListViewModel { Users = _usersService.GetList() }; return(View(model)); }
public async Task <IActionResult> Register([FromBody] RegisterModel model) { // map model to entity var user = _mapper.Map <User>(model); try { // create user await _userService.Add(user, model.Password); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <ActionResult <User> > Post([FromBody] RegistrationModel request) { _logger.LogInformation("Registering new user..."); _logger.LogInformation($"alias: {request.Alias}"); try { // Calls business that triggers workflow start signal execution // await _userBusiness.UserRegistration(request); // return StatusCode(StatusCodes.Status200OK); var result = await _usersService.Add(request); return(new JsonResult(result)); } catch (Exception ex) { _logger.LogError(ex, $"Error calling user registration for user {request.Alias}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public ActionResult Create([Bind(Include = "id_user,login,password,first_name,last_name,email,status")] Users users) { if (!ModelState.IsValid) { ViewBag.Type = "create"; return(View(users)); } try { Users foundUser = usersService.FindByName(users.login); if (foundUser != null) { throw new UserNameAlreadyExistsException(); } } catch (UserNameAlreadyExistsException ex) { ViewBag.Type = "create"; TempData["Status"] = "invalid"; TempData["Msg"] = "Taki użytkownik już istnieje!"; return(View(users)); } catch (UserNotFoundException ex) { } try { users.Roles = rolesService.FindByName("Wykładowca"); users.password = FormsAuthentication.HashPasswordForStoringInConfigFile(users.password, "md5"); usersService.Add(users); TempData["Status"] = "success"; TempData["Msg"] = "Nowy wykładowca został dodany!"; } catch (Exception e) { TempData["Status"] = "invalid"; TempData["Msg"] = "Nie udało się dodać nowego wykładowcy!"; } return(RedirectToAction("List")); }
private void AddUser() { User user; var email = _ioHelper.GetTextFromUser("Provide an email"); if (!_ioHelper.ValidateEmail(email)) { _ioHelper.DisplayInfo("Email must contain \'@\' character!\n", MessageType.Error); return; } if (_usersService.CheckIfUserExists(email)) { _ioHelper.DisplayInfo("User with given email already exists!\n", MessageType.Error); return; } user = new User() { Email = email, FirstName = _ioHelper.GetTextFromUser("Enter your first name"), LastName = _ioHelper.GetTextFromUser("Enter your last name"), Address = new Address() { Street = _ioHelper.GetTextFromUser("Enter street name"), Number = _ioHelper.GetUintFromUser("Enter building number"), City = _ioHelper.GetTextFromUser("Enter city name"), ZipCode = _ioHelper.GetTextFromUser("Enter zip code"), }, UserType = (UserType)Convert .ToInt32(_ioHelper.GetIntFromUser("Enter user type (1 - customer, 2 - courier)")) }; user.Position = _usersService.GetUserPosition(user.Address); _usersService.Add(user); _ioHelper.DisplayInfo("User added successfully!\n", MessageType.Success); }
private void Add() { var createUser = new CreateUserDto(); createUser.FirstName = FirstName; createUser.LastName = LastName; createUser.Login = Login; createUser.Password = Password; createUser.Role = IsAdmin ? RoleEnum.ADMIN : RoleEnum.USER; var results = new List <ValidationResult>(); var context = new ValidationContext(createUser); if (!Validator.TryValidateObject(createUser, context, results, true)) { _dialogsService.ShowError("Заполните все поля формы."); return; } _usersService.Add(createUser); _navigationService.ShowPage(PageNameConstants.UsersPage); _snackbarService.Show("Пользователь успешно добавлен."); }
public async Task <int> Post(Users entity) { var rlt = await _usersService.Add(entity); return(rlt); }
public ActionResult Add(TeacherViewModel model) { UserDto user = ViewBag.User as UserDto; Users teacher = new Users { UserName = model.UserName, HashPassword = Security.StrToMD5(model.Password), RealName = model.RealName, Email = model.Email, Phone = model.Phone, RoleId = model.RoleId, IsActive = true, IsDeleted = false }; int result = 0; if (model.Id > 0)//编辑 { teacher.LastModificationTime = DateTime.Now; teacher.LastModifierUserId = user.UserId; var propertyNames = model.GetType().GetProperties() .Where(p => p.Name != "Id") .Select(p => p.Name) .ToList(); propertyNames.Add("HashPassword"); result = _usersService.UpdateBy(teacher, p => p.Id == model.Id, true, propertyNames.ToArray()); if (result > 0) { return(Json(new { Status = 1, Message = "编辑成功" })); } else { return(Json(new { Status = 0, Message = "编辑失败" })); } } else//新增 { teacher.CreationTime = DateTime.Now; teacher.CreatorUserId = user.UserId; result = _usersService.Add(teacher); if (result > 0) { return(Json(new { Status = 1, Message = "新增成功" })); } else { return(Json(new { Status = 0, Message = "新增失败" })); } } }
public async Task <bool> AddUser(UserDto user) { return(await usersService.Add(user, LoggedUser?.Token)); }
/// <summary> /// Logs the user in or creates the user account if the user does not exist. /// Sets the logged user in the session. /// </summary> public static int OpenIdFinishLogin(IAuthenticationResponse response, SessionWrapper session, IUsersService service, bool enableClaimsRequest) { string externalId = response.ClaimedIdentifier.ToString(); User user = service.GetByProviderId(AuthenticationProvider.OpenId, externalId); var claimsResponse = response.GetExtension<ClaimsResponse>(); string name = enableClaimsRequest ? claimsResponse.Nickname : response.FriendlyIdentifierForDisplay; if (user == null) { user = new User(0, name); if (enableClaimsRequest) { user.Email = claimsResponse.Email; user.BirthDate = claimsResponse.BirthDate; } user = service.Add(user, AuthenticationProvider.OpenId, externalId); } else { if (enableClaimsRequest && !claimsResponse.Email.Equals(user.Email, StringComparison.CurrentCultureIgnoreCase)) { user.Email = claimsResponse.Email; service.Edit(user); } } session.SetUser(user, AuthenticationProvider.OpenId); return user.Id; }
public void POST(Users users) { _usersservice.Add(users); }
public IActionResult Add(User model) { service.Add(model); return(RedirectToAction("Index")); }
public HttpResponseMessage Post(HttpRequestMessage req, [FromBody] Users value) { HttpResponseMessage result = null; string userId = null; #region InputCheck try { if (value == null) { result = Request.CreateResponse(HttpStatusCode.Unauthorized); result.Content = new StringContent(JsonConvert.SerializeObject("Invalid Parameters"), Encoding.UTF8, "application/json"); return(result); } if (usersService.GetById(value.Id) != null) { result = Request.CreateResponse(HttpStatusCode.Found); result.Content = new StringContent(JsonConvert.SerializeObject("User already exist"), Encoding.UTF8, "application/json"); return(result); } if (companyService.GetById(value.CompanyId) == null) { result = Request.CreateResponse(HttpStatusCode.NotFound); result.Content = new StringContent(JsonConvert.SerializeObject("The company doesn't exist"), Encoding.UTF8, "application/json"); return(result); } } catch (System.Exception tEx) { System.Exception raisedException = tEx; result = Request.CreateResponse(HttpStatusCode.InternalServerError); result.Content = new StringContent(JsonConvert.SerializeObject(raisedException), Encoding.UTF8, "application/json"); } try { string token = req.Headers.Authorization.ToString(); userId = utils.checkToken(token); } catch (Exception tEx) { result = Request.CreateResponse(HttpStatusCode.Unauthorized); result.Content = new StringContent(JsonConvert.SerializeObject("Unauthorized access"), Encoding.UTF8, "application/json"); return(result); } #endregion try { usersService.Add(value); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StringContent(JsonConvert.SerializeObject("Insert operation is a success"), Encoding.UTF8, "application/json"); } catch (System.Exception tEx) { System.Exception raisedException = tEx; result = Request.CreateResponse(HttpStatusCode.InternalServerError); result.Content = new StringContent(JsonConvert.SerializeObject("Insert operation failed"), Encoding.UTF8, "application/json"); } return(result); }
/// <summary> /// Logs the user in or creates the a site user account if the user does not exist, based on membership user. /// Sets the logged user in the session. /// </summary> /// <exception cref="ValidationException"></exception> /// <returns>The user id of the authenticated user</returns> public static int TryFinishMembershipLogin(SessionWrapper session, MembershipUser membershipUser, IUsersService service) { if (membershipUser == null) { throw new ArgumentNullException("Can not finish membership signin with membership not set."); } var siteUser = service.GetByProviderId(AuthenticationProvider.Membership, membershipUser.ProviderUserKey.ToString()); if (siteUser == null) { //User does not exist on Nearforums db siteUser = new User(); siteUser.UserName = membershipUser.UserName; siteUser.Email = membershipUser.Email; siteUser = service.Add(siteUser, AuthenticationProvider.Membership, membershipUser.ProviderUserKey.ToString()); } session.SetUser(siteUser, AuthenticationProvider.Membership); return siteUser.Id; }
public void Save() { UserService.Add(User); }