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);
- }