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
ahmed elbarbary
NA
1.6k
278.7k
How to return message user already exist when calling checku
Jan 20 2020 6:14 AM
I make function create user on database by web API asp.net core and it working without
any problem .
I notice more users repeated so that i need to prevent user repeating records on
database .
I make function CheckUserName to check user name exist on database on table user login
if exist prevent clients from add or create new user in case of exist
My problem in case of user exist I need to return "user already exist" on return type
of calling function CheckUserName "user already exist"
but How to return user already exist message
What I have tried:
[Produces(
"application/json"
)]
[Route(
"api/UserLogins"
)]
public
class UserLoginsController : Controller
{
private readonly IUserLogins _services;
public
UserLoginsController(IUserLogins Services)
{
this._services = Services;
}
}
[HttpPost]
public
UserLogins Post([FromBody]UserLogins userDto)
{
if (_services.CheckUserName(userDto.UserName))
{
return
?????????????
}
return
_services.
Create
(userDto);
}
public
class UserLogins:SharedValues
{
public
int
UserLoginID { get;
set
; }
public
string UserName { get;
set
; }
public
string UserMail { get;
set
; }
public
string UserPass { get;
set
; }
public
int
FkTeamID { get;
set
; }
public
Boolean IsAdmin { get;
set
; }
}
public
interface IUserLogins
{
UserLogins
Create
(UserLogins
user
);
bool CheckUserName(string username);
}
Reply
Answers (
1
)
Nested datalist
How do i cache data and update if its changes in database