public bool Update( UpdateUserOptions options) { if (options == null) { return(false); } var user = Search( new SearchUserOptions() { Id = options.UserId }).SingleOrDefault(); if (!string.IsNullOrWhiteSpace(options.FirstName)) { user.FirstName = options.FirstName; } if (!string.IsNullOrWhiteSpace(options.LastName)) { user.LastName = options.LastName; } if (!string.IsNullOrWhiteSpace(options.UserName)) { user.UserName = options.UserName; } if (context_.SaveChanges() > 0) { return(true); } return(false); }
public User UpdateUser(int id, UpdateUserOptions options) { if (options == null) { return(null); } var user = GetUserById(id); if (user == null) { return(null); } if (!string.IsNullOrWhiteSpace(options.FirstName)) { user.FirstName = options.FirstName; } if (!string.IsNullOrWhiteSpace(options.LastName)) { user.LastName = options.LastName; } if (!string.IsNullOrWhiteSpace(options.Address)) { user.Address = options.Address; } if (!string.IsNullOrWhiteSpace(options.Email) && options.Email.Contains("@")) { user.Email = options.Email; } context_.SaveChanges(); return(user); }
public IActionResult Update(int id, [FromBody] UpdateUserOptions options) { var result = userService.UpdateUser(options, id); if (!result.Success) { return(StatusCode((int)result.ErrorCode, result.ErrorText)); } return(Ok()); }
public IActionResult UpdateUserPersonalInfo(string id, [FromBody] UpdateUserOptions options) { var userId = int.Parse(id); var update = userService_.UpdateUser(userId, options); if (update.Success) { return(Json(update.Data)); } return(StatusCode((int)update.ErrorCode, update.ErrorText)); }
public IActionResult UpdateUser([FromBody] UpdateUserOptions options) { var result = _userService.UpdateUser(Globals.UserId, options); if (!result.Success) { return(StatusCode((int)result.ErrorCode, result.ErrorText)); } return(Ok()); }
public IActionResult Update(UpdateUserOptions options) //options { if (options == null) { return(BadRequest()); } _userService.Update(options); //update _basicService.Complete(); return(Ok()); }
public IActionResult Update( [FromBody] UpdateUserOptions options) { var result = userService.UpdateUser(options.UserId, options); if (!result.Success) { return(StatusCode((int)result.ErrorCode, result.ErrorText)); } return(Json(result.Data));; }
public Result <bool> UpdateUser(int userId, UpdateUserOptions options) { if (options == null) { return(Result <bool> .CreateFailed(StatusCode.BadRequest, "Null options")); } var user = GetUserById(userId).Data; if (user == null) { return(Result <bool> .CreateFailed(StatusCode.BadRequest, $"User with {userId} was not found")); } string emailCheck = null; string userNameCheck = null; if (!(options.Email == user.Email)) { emailCheck = options.Email; } if (!(options.UserName == user.UserName)) { userNameCheck = options.UserName; } if (IsDuplicate(emailCheck, userNameCheck)) { return(Result <bool> .CreateFailed(StatusCode.BadRequest, "The username or Email already exists")); } if (user.IsValidUsername(options.UserName)) { user.UserName = options.UserName; } if (user.IsValidEmail(options.Email)) { user.Email = options.Email; } if (context_.SaveChanges() == 0) { return(Result <bool> .CreateFailed(StatusCode.InternalServerError, "User could not be updated")); } return(Result <bool> .CreateSuccessful(true)); }
public User UpdateUser(int id, UpdateUserOptions options) { if (options == null) { return(null); } var user = GetUserById(id); if (user == null) { return(null); } if (!string.IsNullOrWhiteSpace(options.FirstName)) { user.FirstName = options.FirstName; } if (!string.IsNullOrWhiteSpace(options.LastName)) { user.LastName = options.LastName; } if (!string.IsNullOrWhiteSpace(options.Address)) { user.Address = options.Address; } if (!string.IsNullOrWhiteSpace(options.Email)) { user.FirstName = options.FirstName; } if (options.YearOfBirth != null) { user.YearOfBirth = options.YearOfBirth; } return(user); }
public User CreateUser([FromRoute] int id, [FromBody] UpdateUserOptions options) { return(_userService.UpdateUser(id, options)); }
public Result <User> UpdateUser(int userId, UpdateUserOptions options) { var result = new Result <User>(); if (options == null) { result.ErrorCode = StatusCode.BadRequest; result.ErrorText = "Null options"; return(result); } var user = GetById(userId) .Include(x => x.CreatedProjectsList) .Include(c => c.BackedProjectsList) .SingleOrDefault(); if (user == null) { result.ErrorCode = StatusCode.NotFound; result.ErrorText = $"User with id {userId} was not found"; return(result); } if (!string.IsNullOrWhiteSpace(options.FirstName)) { user.FirstName = options.FirstName; } if (!string.IsNullOrWhiteSpace(options.Country)) { user.Country = options.Country; } if (!string.IsNullOrWhiteSpace(options.Description)) { user.Description = options.Description; } if (!string.IsNullOrWhiteSpace(options.Email)) { user.Email = options.Email; } if (!string.IsNullOrWhiteSpace(options.LastName)) { user.LastName = options.LastName; } var rows = 0; try { rows = context.SaveChanges(); } catch (Exception ex) { return(Result <User> .ActionFailed( StatusCode.InternalServerError, ex.ToString())); } if (rows <= 0) { return(Result <User> .ActionFailed( StatusCode.InternalServerError, "User could not be updated")); } return(Result <User> .ActionSuccessful(user)); }
public Result <bool> UpdateUser(UpdateUserOptions options, int id) { var result = new Result <bool>(); if (options == null) { result.ErrorCode = StatusCode.BadRequest; result.ErrorText = "Null options"; return(result); } var user = GetUserById(id); if (user == null) { result.ErrorCode = StatusCode.NotFound; result.ErrorText = $"User with id {id} was not found"; return(result); } if (options.FirstName != null) { user.FirstName = options.FirstName; } if (options.LastName != null) { user.LastName = options.LastName; } if (options.Email != null) { if (string.IsNullOrWhiteSpace(options.Email)) { result.ErrorCode = StatusCode.BadRequest; result.ErrorText = $"Email address is null or empty"; return(result); } //options.Email = options.Email.Trim(); //if (options.Email.Contains("@") && options.Email.EndsWith(".com")) //{ // user.Email = options.Email; //} //else //{ // result.ErrorCode = StatusCode.BadRequest; // result.ErrorText = $"Email submitted is not a valid email address"; // return result; //} if (IsValidEmail(options.Email)) { user.Email = options.Email.Trim(); } else { result.ErrorCode = StatusCode.BadRequest; result.ErrorText = $"Email submitted is not a valid email address"; return(result); } } if (dbContext.SaveChanges() > 0) { result.ErrorCode = StatusCode.OK; result.Data = true; return(result); } result.ErrorCode = StatusCode.InternalServerError; result.ErrorText = $"User could not be updated"; return(result); }
public Result <bool> UpdateUser(int?userId, UpdateUserOptions options) { options.Email = options.Email?.Trim(); options.FirstName = options.FirstName?.Trim(); options.LastName = options.LastName?.Trim(); options.Address = options.Address?.Trim(); try { var user = _context.Set <User>().SingleOrDefault(u => u.UserId == userId); if (user == null) { return(Result <bool> .Failed(StatusCode.NotFound, "User not found")); } if (!string.IsNullOrWhiteSpace(options.FirstName)) { user.FirstName = options.FirstName; } if (!string.IsNullOrWhiteSpace(options.Email)) { var validEmail = user.IsValidEmail(options.Email); if (validEmail) { user.Email = options.Email; } else { return(Result <bool> .Failed(StatusCode.BadRequest, "Invalid Email")); } user.Email = options.Email; } else { return(Result <bool> .Failed(StatusCode.BadRequest, "Email cannot be empty")); } if (!string.IsNullOrWhiteSpace(options.LastName)) { user.LastName = options.LastName; } if (!string.IsNullOrWhiteSpace(options.Address)) { user.Address = options.Address; } var rows = 0; try { rows = _context.SaveChanges(); } catch (Exception ex) { return(Result <bool> .Failed(StatusCode.InternalServerError, ex.Message)); } return(rows <= 0 ? Result <bool> .Failed(StatusCode.BadRequest, "No Changes Applied") : Result <bool> .Succeed(true)); } catch (Exception ex) { return(Result <bool> .Failed(StatusCode.InternalServerError, ex.Message)); } }