public ActionResult Search(Employee employee, string dateFrom, string dateTo) { var context = new Context(); // ViewData["employee"] = default(Employee); // if (!string.IsNullOrEmpty(employeeId)) // { // ViewData["employee"] = new EmployeeRepository(context).Read(Convert.ToInt32(employeeId)); // } DateTime dateFromParsed = default(DateTime); if (!string.IsNullOrEmpty(dateFrom) && !DateTime.TryParse(dateFrom, out dateFromParsed)) { ModelState.AddModelError("dateFrom", "error parsing dateFrom"); } ViewData["dateFrom"] = dateFromParsed; DateTime dateToParsed = default(DateTime); if (!string.IsNullOrEmpty(dateTo) && !DateTime.TryParse(dateTo, out dateToParsed)) { ModelState.AddModelError("dateTo", "error parsing dateTo"); } ViewData["dateTo"] = dateToParsed; var orders = new Order[0]; if (ModelState.IsValid) { orders = new OrderRepository(context).Search((Employee)ViewData["employee"], (DateTime)ViewData["dateFrom"], (DateTime) ViewData["dateFrom"]); } return View(orders); }
public static void Set(Context context) { HttpContext.Current.Items["Context"] = context; }