public virtual ActionResult LogRepair(Models.Job.LogRepairModel m, FormCollection form) { m.UpdateModel(Database, true); if (ModelState.IsValid) { switch (m.SubmissionAction) { case "Update": var updatedModel = new Models.Job.LogRepairModel() { JobId = m.JobId, RepairProviderId = m.RepairProviderId, OrganisationAddressId = m.OrganisationAddressId, RepairDescription = m.RepairDescription, PublishAttachmentIds = m.PublishAttachmentIds, PublishAttachments = m.PublishAttachments }; updatedModel.UpdateModel(Database, false); if (updatedModel.RepairProvider != null) { using (var wp = updatedModel.RepairProvider.CreateInstance<RepairProviderFeature>()) { using (var rp = m.RepairProvider.CreateInstance<RepairProviderFeature>()) { m.RepairProviderSubmitJobBeginResult = rp.SubmitJobBegin(Database, this, updatedModel.Job, updatedModel.OrganisationAddress, updatedModel.TechUser); } } } return View(updatedModel); case "Manual": if (string.IsNullOrWhiteSpace(m.ManualProviderName)) { ModelState.AddModelError("ManualProviderName", "The Repair Provider Name is required"); return View(Views.LogRepair, m); } try { m.Job.OnLogRepair(Database, m.RepairDescription, m.ManualProviderName, m.ManualProviderReference, m.OrganisationAddress, m.TechUser); Database.SaveChanges(); return RedirectToAction(MVC.Job.Show(m.JobId)); } catch (Exception ex) { ex.ToExceptionless().Submit(); m.Error = ex; return View(Views.LogRepairError, m); throw; } case "Disclose": using (var p = m.RepairProvider.CreateInstance<RepairProviderFeature>()) { Dictionary<string, string> warrantyProviderProperties; try { warrantyProviderProperties = p.SubmitJobParseProperties(Database, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.RepairDescription); } catch (Exception ex) { ex.ToExceptionless().Submit(); m.Error = ex; return View(Views.LogRepairError, m); } if (!ModelState.IsValid) return View(Views.LogRepair, m); if (warrantyProviderProperties != null) { m.ProviderPropertiesJson = JsonConvert.SerializeObject(warrantyProviderProperties); } m.DiscloseProperties = p.SubmitJobDiscloseInfo(Database, m.Job, m.OrganisationAddress, m.TechUser, m.RepairDescription, warrantyProviderProperties); return View(Views.LogRepairDisclose, m); } case "Submit": try { m.Job.OnLogRepair(Database, m.RepairDescription, m.PublishAttachments, m.RepairProvider, m.OrganisationAddress, m.TechUser, m.ProviderProperties()); Database.SaveChanges(); return RedirectToAction(MVC.Job.Show(m.JobId)); } catch (Exception ex) { ex.ToExceptionless().Submit(); m.Error = ex; return View(Views.LogRepairError, m); throw; } default: return RedirectToAction(MVC.Job.Show(m.JobId)); } } else { return View(Views.LogRepair, m); } }
public virtual ActionResult LogRepair(int id, string RepairProviderId, int? OrganisationAddressId) { var m = new Models.Job.LogRepairModel() { JobId = id, RepairProviderId = RepairProviderId, OrganisationAddressId = OrganisationAddressId }; m.UpdateModel(Database, false); m.RepairDescription = m.Job.GenerateFaultDescription(Database); if (m.RepairProvider != null) { using (var rp = m.RepairProvider.CreateInstance<RepairProviderFeature>()) { m.RepairProviderSubmitJobBeginResult = rp.SubmitJobBegin(Database, this, m.Job, m.OrganisationAddress, m.TechUser); } } return View(m); }