Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ViewModel
- public class SupportEventViewModel
- {
- public SupportEvent SupportEvent { get; set; }
- public IEnumerable<SelectListItem> AllEmployees { get; set; }
- private List<int> selectedEmployees;
- public List<int> SelectedEmployees
- {
- get
- {
- if (selectedEmployees == null)
- {
- selectedEmployees = SupportEvent
- .Employees
- .Select(m => m.Id)
- .ToList();
- }
- return selectedEmployees;
- }
- set { selectedEmployees = value; }
- }
- }
- // SupportEventController - Edit()
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(SupportEventViewModel model, bool? active)
- {
- foreach(var e in model.SelectedEmployees)
- {
- model.SupportEvent.Employees
- .Add(db.Employees.Find(e));
- }
- if (ModelState.IsValid)
- {
- db.Entry(model.SupportEvent).State = EntityState.Modified;
- db.SaveChanges();
- return RedirectToAction(((bool)active) ?
- "ActiveTicketDetails" : "Details", "Ticket", new { id = model.SupportEvent.TicketId });
- }
- return View(model);
- }
- // The partial view/form
- @model ProjectWhiteWave.ViewModels.SupportEventViewModel
- @{
- Layout = null;
- }
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title></title>
- </head>
- <body>
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>SupportEvent</h4>
- <hr />
- @Html.ValidationSummary(true)
- @Html.HiddenFor(model => model.SupportEvent.SupportEventId)
- <div class="form-group">
- @Html.LabelFor(model => model.SupportEvent.DateOpened, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.SupportEvent.DateOpened)
- @Html.ValidationMessageFor(model => model.SupportEvent.DateOpened)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.SupportEvent.DateClosed, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.SupportEvent.DateClosed)
- @Html.ValidationMessageFor(model => model.SupportEvent.DateClosed)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.AllEmployees, "Technicians", new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.ListBoxFor(model => model.SelectedEmployees, Model.AllEmployees)
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.SupportEvent.Description, new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.SupportEvent.Description)
- @Html.ValidationMessageFor(model => model.SupportEvent.Description)
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Save" class="btn btn-default" />
- </div>
- </div>
- </div>
- </body>
- </html>
- model.SupportEvent.Employees.Add(db.Employees.Find(e));
- model.SupportEvent.Employees.Add(db.Employees.Find(emp => emp.Id = e));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement