private bool CheckForEmptyProperies(RegisterModel model) { foreach (PropertyInfo property in model.GetType().GetProperties()) { if (String.IsNullOrEmpty((string)property.GetValue(model, null))) { return(false); } } return(true); }
public static string TurnModelToString(RegisterModel model) { var getProperties = model.GetType().GetProperties(); StringBuilder sb = new StringBuilder(); foreach (PropertyInfo property in getProperties) { var propValue = property.GetValue(model, null); if (property.Name == Enum.GetName(typeof(ModelProperties), ModelProperties.Password) || property.Name == Enum.GetName(typeof(ModelProperties), ModelProperties.ConfirmPassword)) { continue; } sb.Append(string.Format($"{property.Name}: {propValue} ")); } return(sb.ToString()); }
public IActionResult Register([FromBody] RegisterModel model) { foreach (PropertyInfo property in model.GetType().GetProperties()) { if ((string)property.GetValue(model, null) == "") { return(BadRequest("Don't leave empty fields")); } } if (model.Password == model.ConfirmPassword) { model.Role = "User"; _userService.RegisterUser(model); return(Ok("Successfully registered!")); } return(BadRequest("Something went wrong, try again")); }