public async Task <ActionResult> Create(CodeView view) { CodeRepository codeRepo; try { using (DBConnection dbc = new DBConnection(settings.Database.ConnectionString, logger)) { codeRepo = new CodeRepository(settings, logger, dbc); if (ModelState.IsValid) { await codeRepo.Add(view.Code); return(RedirectToAction("Index", "Code")); } view.CodeCategories = CodeCategory.GetList(); return(View("Create", view)); } } catch (Exception ex) { throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace); } }
public async Task <ActionResult> Edit(int id) { CodeRepository codeRepo; CodeView view = new CodeView() { Code = new Code() { Active = true }, CodeCategories = new List <CodeCategory>() }; try { using (DBConnection dbc = new DBConnection(settings.Database.ConnectionString, logger)) { codeRepo = new CodeRepository(settings, logger, dbc); view.Code = await codeRepo.FindByPKView(new PrimaryKey() { Key = id, IsIdentity = true }); view.CodeCategories = CodeCategory.GetList(); } } catch (Exception ex) { throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace); } return(View("Edit", view)); }
public async Task <ActionResult> Create() { CodeView view = new CodeView() { Code = new Code() { Active = true }, CodeCategories = new List <CodeCategory>() }; try { view.CodeCategories = CodeCategory.GetList(); } catch (Exception ex) { throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace); } return(await System.Threading.Tasks.Task.Run(() => View("Create", view))); }