ahmed elbarbary

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
 
  1. What I have tried:  
  2.   
  3.   
  4. [Produces("application/json")]  
  5.     [Route("api/UserLogins")]  
  6.     public class UserLoginsController : Controller  
  7.     {  
  8.         private readonly IUserLogins _services;  
  9.         public UserLoginsController(IUserLogins Services)  
  10.         {  
  11.             this._services = Services;  
  12.         }  
  13.      }  
  14.         [HttpPost]  
  15.         public UserLogins Post([FromBody]UserLogins userDto)  
  16.         {  
  17.             if (_services.CheckUserName(userDto.UserName))  
  18.             {  
  19. return ?????????????  
  20.             }  
  21.             return  _services.Create(userDto);  
  22.             
  23.         }  
  24. public class UserLogins:SharedValues  
  25.     {  
  26.         public int UserLoginID { get; set; }  
  27.         public string UserName { get; set; }  
  28.         public string UserMail { get; set; }  
  29.         public string UserPass { get; set; }  
  30.         public int FkTeamID { get; set; }  
  31.         public Boolean IsAdmin { get; set; }  
  32.   
  33.   
  34.     }  
  35.    
  36.  public interface IUserLogins  
  37.     {  
  38.         UserLogins Create(UserLogins user);  
  39.         bool CheckUserName(string username);  
  40.     }  
 

Answers (1)