title: how to prevent a user from booking appointment on same date & time in c#?
body: <p>What can I add to the if statement to compare time so once the date is same it moves on to checking the time and let the user know if the time is already booked ?</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create(Appointment appointment)
  {
      try
      {
         string UserName = User.Identity.Name;
         appointment.username = UserName;
  
         DateTime date1 = appointment.AppointmentDateTime.Date;
  
         IEnumerable&lt;Appointment&gt; ApntDate = db.Appointment.ToList().Where(q=&gt; q.AppointmentDateTime.Date == date1);                   
  
         if (ApntDate != null)
         {
              DateTime time = System.DateTime.Now;
              for (int i = 0; i &lt; ApntDate.Count(); i++)
              {
                   if (date1 == ApntDate.ElementAt(i).AppointmentDateTime)
                   {
  
                   }
              }
          }
  
          db.Appointment.Add(appointment);
          db.SaveChanges();
  
          return RedirectToAction("Index", "Appointment");       
      }
      catch (Exception ex)
      {
        return View(ex.ToString());
      }
   }
  </code></pre>