Working in visual studio and have the current code in my controller class called GroupController. On the groups page, I can create a new group. The user will then enter String values for groupName, groupAssignment, groupLocation, and GroupDateTime. The code I have so far is provided below, but have struggled to find a working comparison for dates. I want to make sure that Input date is greater than the current date. If not, it will not allow the user to create a group. Any suggestions? Thank you
public ActionResult Create([Bind(Include = "GroupID,GroupName,GroupAssignment,GroupLocation,GroupDateTime")] Group group)
{
var currentUser = manager.FindById(User.Identity.GetUserId());
try
{
group.User = manager.FindById(User.Identity.GetUserId());
db.Groups.Add(group);
db.SaveChanges();
return RedirectToAction("Index");
}
catch (Exception /* dex */)
{
if(group.User == null)
{
ModelState.AddModelError("", "No user logged in");
}
else
{
ModelState.AddModelError("", "Unhandled Error");
}
}
return View(group);
}
GroupDateTimetoDateTimeand compare it withDateTime.Nowor something?if (group.GroupDateTime < DateTime.Now) { //err}group.GroupDateTimeis astring(is this correct?), so that comparison won't work. You need to convert the string to aDateTimefirst. You should at least do this to determine if you're working will a valid date and time.