So I have this schedule visit page with two groups.
Group 1 contains a list of: Cases.
Group 2 contains a list of: Parties.
each group has a checkboxes next to its item for the user to select.
My Issue when i select a case and/or a party and save -- then go to the edit page of the visit i just saved and only my selected case is checked and the party i selected is not checked. After debugging i realized that the partyId is not being saved properly during the create page and thus not showing as selected or saved on the edit page.
I really need help on how to properly save the party selected and setting for it a value from the parameter. Here is my code of what i have for saving a case and would like to know how to properly save with party.
Controller
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(VisitViewModel viewModel, Guid[] associatedCasesSelected, Guid[] selectedParties)
{
if (!ModelState.IsValid)
{
viewModel.Time = _timeEntryHelper.Value;
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
var visitEntry = Mapper.Map<VisitViewModel, VisitEntry>(viewModel);
...
viewModel.CasePartyIds = selectedParties;
try
{
_visitEntryService.Create(visitEntry, associatedCasesSelected);
this.FlashInfo(string.Format(Message.ConfirmationMessageCreate, Resources.Entities.Visit.EntityName));
}
catch (RulesException ex)
{
ex.CopyTo(ModelState);
}
if (ModelState.IsValid)
return RedirectToAction("Edit", "Case", new { caseId = viewModel.CaseId });
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
VisitEntryService
public void Create(VisitEntry visitEntry,IList<Guid>caseIds)
{
EnsureValid(visitEntry);
_visitEntryRepository.Save(visitEntry);
caseIds = AddCurrentCaseToCases(visitEntry.CaseId, caseIds);
foreach (var caseId in caseIds.Distinct())
{
var visit = new Visit {CaseId = caseId, VisitEntryId = visitEntry.VisitEntryId};
_visitService.Create(visit);
}
}
AddCurrentCaseToCases
private static IList<Guid>AddCurrentCaseToCases(Guid caseId, IEnumerable<Guid>caseIds)
{
var cases = new List<Guid>();
if (caseIds != null)
{
cases.AddRange(caseIds);
if(!caseIds.Contains(caseId))
cases.Add(caseId);
}
else cases.Add(caseId);
return cases;
}
VisitService
public Visit Get(Guid visitId)
{
return DataContext.Visits.SingleOrDefault(v => v.VisitId == visitId);
}
public void Save(Visit visit)
{
if(visit.VisitId == Guid.Empty)
{
visit.VisitId = Guid.NewGuid();
DataContext.Visits.InsertOnSubmit(visit);
}
else
{
var currentVisit = Get(visit.VisitId);
if (currentVisit == null) throw RepositoryExceptionFactory.Create("Visit", "VisitId");
}
DataContext.SubmitChanges();
}
Any TIPS or IDEAS is greatly appreciated at this time :)
The entitiy for the parties will be VisitEntryParty