public async Task <IActionResult> Edit(int id, IFormCollection collection) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // TODO: Add update logic here Ticket ticket = new Ticket(); ticket = new Ticket { TicketId = Convert.ToInt32(collection["TicketId"]), ProjectRefId = Convert.ToInt32(collection["ProjectRefId"]), DeptRefId = Convert.ToInt32(collection["DeptRefId"]), EmpRefId = Convert.ToInt32(collection["EmpRefId"]), Description = collection["Description"], SubmitDate = Convert.ToDateTime(collection["SubmitDate"]), Status = collection["Status"] }; _context.Entry(ticket).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> Edit(int id, IFormCollection collection) { try { // TODO: Add update logic here Ticket ticket = new Ticket(); if (ModelState.IsValid) { ticket = new Ticket { TicketId = Convert.ToInt32(collection["TicketId"]), ProjectRefId = Convert.ToInt32(collection["ProjectRefId"]), DeptRefId = Convert.ToInt32(collection["DeptRefId"].ToString()), EmpRefId = Convert.ToInt32(collection["EmpRefId"].ToString()), Description = collection["Description"], SubmitDate = Convert.ToDateTime(collection["SubmitDate"]), Status = collection["Status"] }; _context.Entry(ticket).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DeptRefId = new SelectList(_context.Departments, "DeptId", "DeptName", ticket.DeptRefId); int _deptId = ticket.DeptRefId; var empList = _context.Employees.Include(t => t.Department).Where(t => t.DeptRefId == _deptId); ViewBag.EmpRefId = new SelectList(empList, "EmpId", "EmpName", ticket.EmpRefId); //new SelectList(_context.Employees, "EmpId", "EmpName", ticket.EmpRefId); ViewBag.ProjectRefId = new SelectList(_context.Projects, "ProjectId", "ProjectTitle", ticket.ProjectRefId); List <SelectListItem> status = new List <SelectListItem>() { new SelectListItem { Text = "Open", Value = "O" }, new SelectListItem { Text = "Close", Value = "C" } }; ViewBag.Status = new SelectList(status, "Value", "Text", ticket.Status); return(View(ticket)); //return RedirectToAction(nameof(Index)); } catch { return(View()); } }