public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { try { using (var db = new NamegiverContext(Configuration)) { var name = new Name() { Infos = new[] { new NameInfo() { Name = this.Name } } }; int newId = await db.Names.AddName(name); Status = $"\"{Name}\" successfully added with id: {newId}"; } } catch (SqlException ex) { Trace.WriteLine(ex.ToString()); Status = $"Database error: {ex.Message}"; } catch (ArgumentException ex) { Trace.WriteLine(ex.ToString()); Status = $"Error: {ex.Message}"; } } return(Page()); }
public async Task <ActionResult <int> > AddName([FromBody] Name name) { using (var db = new NamegiverContext(Configuration)) { return(Ok(await db.Names.AddName(name))); } }
public async Task <ActionResult <string> > GetNameInfoUrl(int id) { using (var db = new NamegiverContext(Configuration)) { return(Ok(await db.Names.GetNameInfoUrl(id))); } }
public async Task <ActionResult <NameInfo> > GetRandomName() { using (var db = new NamegiverContext(Configuration)) { return(Ok(await db.Names.GetRandomNameInfo())); } }
public async Task <ActionResult <IEnumerable <Name> > > GetTopRejectedNames() { using (var db = new NamegiverContext(Configuration)) { return(Ok(await db.Names.GetTopRejectedNames())); } }
public async Task OnGetAsync() { using (var db = new NamegiverContext(Configuration)) { TopList = await db.Names.GetTopRejectedNames(); } }
public async Task <ActionResult> DeleteName(int id) { using (var db = new NamegiverContext(Configuration)) { await db.Names.DeleteName(id); } return(NoContent()); }
public CharacterModel(IConfiguration configuration) { context = new NamegiverContext(configuration); }