public async Task <IActionResult> Create([Bind("ObjectTypeId,Name,Data,Image,Options,StartEnd,ControlTypeId")] ObjectTypeViewModel objectTypeViewModel) { ObjectType objectType = new ObjectType { }; if (ModelState.IsValid) { //Only save if the image is valid or not required if (CheckImage(objectTypeViewModel)) { objectType = await AssignObjectType(objectTypeViewModel); _context.Add(objectType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ViewData["ControlTypeId"] = new SelectList(_context.ControlTypes, "ControlTypeId", "Name", objectType.ControlTypeId); return(View(objectTypeViewModel)); }
public async Task <IActionResult> Create([Bind("FormObjectId,Order,QuestionNo,PageNo,ObjectTypeId")] FormObject formObject, string save) { //This will only trigger when the dropdown has been changed if (save == null) { ViewData["Orders"] = new SelectList(GetNextOrderNoList(isEdit: false, pageNo: formObject.PageNo)); ViewData["PageNo"] = new SelectList(GetPages()); } else { if (ModelState.IsValid) { UpdateOrderNos(formObject); _context.Add(formObject); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ViewData["ObjectTypeId"] = new SelectList(_context.ObjectTypes, "ObjectTypeId", "Name", formObject.ObjectTypeId); return(View(formObject)); }
public async Task <IActionResult> Index(int?page) { int pageNo = page ?? 1; var HelpManualDbContext = _context.FormObject .Include(f => f.ObjectType.ControlType) .OrderBy(x => x.Order); List <int> pages = new List <int>(); foreach (var fo in HelpManualDbContext) { pages.Add(fo.PageNo); } int?maxPage = HttpContext.Session.GetInt32("MaxPage"); //Remembers the max page using a session variable so that if the user goes back to another page //the page that they left will still be enabled if (maxPage == null) { HttpContext.Session.SetInt32("MaxPage", pageNo); } else if (maxPage < pageNo) { HttpContext.Session.SetInt32("MaxPage", pageNo); } ViewBag.MaxPage = HttpContext.Session.GetInt32("MaxPage"); string userName = HttpContext.User.Identity.Name.ToLowerInvariant(); _context.Add(new UserAccess(userName, pageNo)); await _context.SaveChangesAsync(); return(View(await PaginatedList <FormObject> .CreateAsyncHomePage(HelpManualDbContext.AsNoTracking(), pageNo, pages.Distinct().Count()))); }