TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
611
127.8k
Error in c# code .Please check.
Apr 13 2020 1:02 AM
public
async Task<IActionResult> Register([FromBody]SignUp signUp)
{
try
{
SmartWatchUser user = await userManager.FindByEmailAsync(signUp.Email);
if
(user !=
null
)
return
BadRequest(
"Username \""
+ user.Email +
"\" is already taken"
);
SmartWatchUser smartWatchUser =
new
SmartWatchUser
{
Email = signUp.Email,
FirstName = signUp.UserName?.Split(
" "
)?[0],
LastName = signUp.UserName?.Split(
" "
)?[1],
UserName = signUp.Email,
Status = UserStatus.New,
LockoutEnabled =
false
};
var result = await userManager.CreateAsync(smartWatchUser, signUp.Password);
if
(result.Succeeded)
{
var roleResult = await userManager.AddToRoleAsync(smartWatchUser,
"AppUser"
);
return
Ok(
"User Registered Successfully!"
);
}
else
return
Ok(
string
.Join(
","
, result.Errors.Select(a=>a.Description).ToArray()));
}
catch
(Exception ex)
{
//TODO logging
return
StatusCode(500, ex.Message);
}
}
This is my signup code in .net core with entityfram work code first approach. I have face this error 'Index was outside the bounds of the array'. Please solve this what's problem this code.
Reply
Answers (
4
)
getting error while storing date into database in vs2013
How to clear data after Browser back button click ?