mercredi 3 juin 2015

Search Only if not Null value

I am currently writing a search function to search tickets by a Ticket owner, Ticket Tech, Status, etc. However I thought I can just put in if statements in the middle of the Linq statement testing if not null, unfortunately I am getting an error on the if statement that I have in the LINQ statement. Here is my controller code:

 public ActionResult TechSearchTickets()
        {
            ViewBag.StatusId = new SelectList(db.TicketStatuses, "UserId", "FullName");
            ViewBag.UserId = new SelectList(db.Users
                                                .Where(u => u.Status == 1 || u.RoleID == new Guid("00000000-0000-0000-0000-000000000000")), "UserId", "FullName");
            ViewBag.TechId = new SelectList(db.Users
                                                .Where(u => u.Status == 1 || u.RoleID == new Guid("00000000-0000-0000-0000-000000000000")), "UserId", "FullName");

            return View();
        }

        [HttpPost]
        public ActionResult TechSearchTickets(SearchTickets searchTickets)
        {

            var model = db.Tickets
                    .Include(t => t.TicketNotes)
                    if (searchTickets.TechnicianId != null)
                    {
                        .Where(t => t.TechnicianId == g)
                    }
                    .Where(t => t.TicketStatusId == new Guid("553F4C93-4A72-44BD-A9CE-FAB4F87D4E08"))
                    .OrderBy(t => t.OpenDate)
                    .ToList();

            return View("TechClosed", model);


            return View();
        }

Aucun commentaire:

Enregistrer un commentaire