I'm working on a project where I report Time Reports. Right now I am working on a feature where you can report vacation. From and to date. But when you just click the button send without having to enter anything in my two fields it will crash due null exception.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(DateTime fromDate, DateTime toDate, string comment)
{
using (IDatabaseLayer db = new DatabaseLayer())
{
if (fromDate != null || toDate != null)
{
db.InsertVacation(Constants.CurrentUser(User.Identity.Name), fromDate, toDate, comment);
ViewData.Model = db.GetUserVacations(Constants.CurrentUser(User.Identity.Name));
}
}
SendVacationMail(fromDate, toDate, comment);
ViewData["posted"] = true;
return View();
}
When debugging it, it doesn't hit this code block unless my fields have values in them.
&&opereator instead of||null