title: Check if the user already exists in ASP.NET MVC
body: <p>This is the controller:</p>
  
  <pre><code>public class UserController : Controller
  {
      ResturantEntities db = new ResturantEntities();
  
      public ActionResult Index()
      {
          var data = db.User.OrderByDescending(z =&gt; z.ID).Select(s =&gt; s).ToList();
          return View(data);
      }
  
      public ActionResult Register()
      {
  
          return View();
      }
      [HttpPost]
      public ActionResult Register(UserVM obj)
      {
          if (ModelState.IsValid)
          {
  
              User newobj = new User();
              newobj.UserName = obj.UserName;
              newobj.Email = obj.Email;
              newobj.Password = obj.Password;
              newobj.Address = obj.Address;
              db.User.Add(newobj);
              db.SaveChanges();
              return RedirectToAction("Index");
  
          }
          else
          {
              return RedirectToAction("Register");
          }
      }
  }
  </code></pre>
  
  <p>I want to add an if condition before <code>newobj.Email = obj.Email;</code> to check if the email exists in db or not; if not exists so it will be added.</p>