private async Task <ScriptTagsEdit> PopulateSelectListsAsync(ScriptTagsEdit tag) { DateTime now = DateTime.Now; tag.QueueMapSL = await(from c in _context.Codes where c.Category == "QueueMap" && (!_context.ScriptTags.Any(st => c.Code == st.QueueMapCode && st.ScriptId == tag.ScriptTag.ScriptId)) select new SelectListItem { Value = c.Code, Text = c.Label }).ToListAsync(); tag.DataTypeSL = await(from c in _context.Codes where c.Category == "DataType" select new SelectListItem { Value = c.Code, Text = c.Label }).ToListAsync(); tag.DateFormatSL = await(from c in _context.Codes where c.Category == "DateFormat" select new SelectListItem { Value = c.Code, Text = now.ToString(c.Code) }).ToListAsync(); tag.TimeFormatSL = await(from c in _context.Codes where c.Category == "TimeFormat" select new SelectListItem { Value = c.Code, Text = c.Code == "h:mm xx" ? now.ToString("h:mm") + " in the " + (now.Hour < 12 ? "morning": "afternoon") : now.ToString(c.Code) }).ToListAsync(); return(tag); }
public async Task <PartialViewResult> OnGetScriptTagsEditAsync(int id) { ScriptTagsEdit tag = new ScriptTagsEdit { ScriptTag = await _context.ScriptTags.Where(s => s.ScriptTagId == id).FirstOrDefaultAsync(), Action = "Edit" }; return(await ScriptTagsModalAsync(tag)); }
private async Task <PartialViewResult> ScriptTagsModalAsync(ScriptTagsEdit tag) { tag = await PopulateSelectListsAsync(tag); return(new PartialViewResult { ViewName = @".\Scripts\ScriptTags\ScriptTagsModal", ViewData = new ViewDataDictionary <ScriptTagsEdit>(ViewData, tag) }); }
public async Task <PartialViewResult> OnPostScriptTagsUpdateAsync(ScriptTagsEdit tag) { if (ModelState.IsValid) { switch (tag.Action) { case "Create": case "Delete": //Tags are created an deleted when the script is modified. They are based upon the tags used the message script. break; case "Edit": _context.ScriptTags.Update(tag.ScriptTag); await _context.SaveChangesAsync(); break; } } tag = await PopulateSelectListsAsync(tag); return(await ScriptTagsModalAsync(tag)); }