public ActionResult EditLogbookEntry(Guid logbookEntryId) { var model = new EditLogbookEntryViewModel(); var entry = DataAccess.GetLogbookEntry(logbookEntryId); var selections = DataAccess.GetSelectedFields(logbookEntryId); model.Activities = DataAccess.GetActivitiesForUser(Guid.Parse(User.Identity.GetUserId())); model.LogbookId = entry.LogbookId; model.LogbookEntryId = logbookEntryId; model.EntryDate = entry.EntryDate; model.ActivityId = entry.ActivityId; model.Notes = entry.Notes; model.LogbookEntryFields = DataAccess.GetFieldOptionMappings(Guid.Parse(User.Identity.GetUserId()), model.ActivityId); foreach (var field in model.LogbookEntryFields) { field.ActivityFieldOptionMappings = DataAccess.GetFieldOptionMappings(field.FieldId); } foreach (var selection in selections) { if (selection.FieldOptionId == Guid.Empty) { model.LogbookEntryFields.Single(f => f.FieldId == selection.FieldId).CustomText = selection.OptionText; } else { model.LogbookEntryFields.Single(f => f.FieldId == selection.FieldId) .ActivityFieldOptionMappings.Single(m => m.FieldOptionId == selection.FieldOptionId) .Selected = true; } } return(View(model)); }
public async Task <ActionResult> AddLogbookEntry(EditLogbookEntryViewModel model) { var userId = Guid.Parse(User.Identity.GetUserId()); var logbook = new LogbookEntryDTO(); logbook.LogbookId = model.LogbookId; logbook.ActivityId = model.ActivityId; logbook.Status = "STATUS/ACTIVE"; logbook.CreatedBy = userId; logbook.UpdatedBy = userId; logbook.CreateDate = DateTime.Now; logbook.UpdateDate = DateTime.Now; logbook.EntryDate = model.EntryDate; logbook.Notes = model.Notes; logbook.EntryFields = model.LogbookEntryFields ?? new LogbookEntryFieldDTO[0]; DataAccess.AddLogbookEntry(logbook, userId); if (logbook.LogbookEntryId == Guid.Empty) { ModelState.AddModelError("", "Failed to create entry"); } else { return(RedirectToAction("Logbook", "Logbook", new { logbookId = logbook.LogbookId })); } return(View(model)); }
public ActionResult AddLogbookEntry(Guid logbookId) { var model = new EditLogbookEntryViewModel(); model.Activities = DataAccess.GetActivitiesForUser(Guid.Parse(User.Identity.GetUserId())); model.LogbookId = logbookId; model.LogbookEntryId = Guid.Empty; model.EntryDate = DateTime.Today; model.ActivityId = DataAccess.GetLogbook(logbookId).DefaultActivityId; model.LogbookEntryFields = DataAccess.GetFieldOptionMappings(Guid.Parse(User.Identity.GetUserId()), model.ActivityId); return(View(model)); }
public async Task <ActionResult> EditLogbookEntry(EditLogbookEntryViewModel model) { var logbook = new LogbookEntryDTO(); logbook.LogbookId = model.LogbookId; logbook.LogbookEntryId = model.LogbookEntryId; logbook.ActivityId = model.ActivityId; logbook.Status = "STATUS/ACTIVE"; logbook.UpdatedBy = Guid.Parse(User.Identity.GetUserId()); logbook.UpdateDate = DateTime.Now; logbook.EntryDate = model.EntryDate; logbook.Notes = model.Notes; logbook.EntryFields = model.LogbookEntryFields ?? new LogbookEntryFieldDTO[0]; DataAccess.UpdateLogbookEntry(logbook); return(RedirectToAction("LogbookEntry", "Logbook", new { logbookEntryId = logbook.LogbookEntryId })); }