public IActionResult Create(int contractID, int groupID) { //string userLogin = GetLogin(); PopulateViewBag(contractID); if (groupID > 0) { try { // id is the LineItemGroup.GroupID var group = _context.LineItemGroups.Where(lig => lig.GroupID == groupID).SingleOrDefault(); if (group == null) { // if it is zero or does not exist, create a new LineItemGroup and set id = its GroupID LineItemGroup newGroup = new LineItemGroup(ViewBag.Contract, ViewBag.CurrentUser) { CurrentStatus = ConstantStrings.Draft, LastEditedUserID = ViewBag.CurrentUser.UserID, OriginatorUserID = ViewBag.CurrentUser.UserID }; _context.LineItemGroups.Add(newGroup); _context.SaveChanges(); group = newGroup; } ViewBag.lineItemGroup = group; ViewBag.contractID = ViewBag.Contract.ContractID; // also the View does not use this to populate a selection list yet. //ViewData["FlairLineIDs"] = GetAmendmentsList(contractID); } catch (Exception e) { _logger.LogError("LineItemsController.Create Error:" + e.GetBaseException()); Log.Error("LineItemsController.Create Error:" + e.GetBaseException() + "\n" + e.StackTrace); } } ViewBag.LineItemTypes = ConstantStrings.GetLineItemTypeList(); ViewBag.currentFiscalYear = PermissionsUtils.GetCurrentFiscalYear(); ViewData["Categories"] = _context.Categories.OrderBy(v => v.CategoryCode); ViewData["StatePrograms"] = _context.StatePrograms.OrderBy(v => v.ProgramCode); return(View()); }