public async Task <IViewComponentResult> InvokeAsync(string id, string ownerLevel, string ownerId) { if (string.IsNullOrEmpty(id)) { return(new ViewComponentPlaceholder()); } var note = await _assignmentManager.GetAssignmentAsync(id); if (note == null) { return(new ViewComponentPlaceholder()); } var model = note.CloneToAssignmentDetailsViewModel(); await LoadUserGroupsAsync(model, id); await LoadCategoriesAsync(model, id); model.TimeZoneName = TimeZoneHelper.NameOfTimeZoneId(model.TimeZoneId); ViewData["ownerLevel"] = ownerLevel ?? string.Empty; ViewData["ownerId"] = ownerId ?? string.Empty; return(await Task.Run(() => { return View("AssignmentDetailsView", model); })); }
public async Task <IViewComponentResult> InvokeAsync(string id, string ownerLevel, string ownerId, string categoryId) { if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(ownerLevel)) { return(new ViewComponentPlaceholder()); } ViewData["ownerLevel"] = ownerLevel ?? string.Empty; ViewData["ownerId"] = ownerId ?? string.Empty; ViewData["TimeZoneList"] = TimeZoneHelper.GetTimeZoneSelectList(); AssignmentDetailsViewModel model; if (string.IsNullOrEmpty(id)) { // Create new assignment model = new AssignmentDetailsViewModel() { Id = string.Empty, OwnerLevel = (OwnerLevel)Enum.Parse(typeof(OwnerLevel), ownerLevel), OwnerId = ownerId, Status = AssignmentStatus.Draft, DueDT = DateTime.Now.AddDays(3), TimeZoneId = TimeZoneHelper.DefaultTimeZoneId, TimeZoneName = TimeZoneHelper.NameOfTimeZoneId(TimeZoneHelper.DefaultTimeZoneId), AllowComments = false, SendNotification = false }; if (!string.IsNullOrEmpty(categoryId)) { var category = await _assignmentManager.GetCategoryAsync(categoryId); if (category != null) { model.Categories.Add(category); model.CategoryIds.Add(categoryId); } } return(View("AssignmentDetailsCreate", model)); } else { // Load existing assignment var note = await _assignmentManager.GetAssignmentAsync(id); if (note == null) { return(new ViewComponentPlaceholder()); } model = note.CloneToAssignmentDetailsViewModel(); if (string.IsNullOrEmpty(model.TimeZoneId)) { model.TimeZoneId = TimeZoneHelper.DefaultTimeZoneId; // TO DO: Get the default time zone from the user context. model.DueDT = TimeZoneHelper.Now(model.TimeZoneId); } model.TimeZoneName = TimeZoneHelper.NameOfTimeZoneId(model.TimeZoneId); await LoadCategoriesAsync(model, id); await LoadUserGroupsAsync(model, id); if (note.Status == AssignmentStatus.Draft) { return(View("AssignmentDetailsEdit", model)); } else { return(View("AssignmentDetailsView", model)); } } }