Esempio n. 1
0
        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());
        }
Esempio n. 2
0
 public async Task <ActionResult <int> > AddName([FromBody] Name name)
 {
     using (var db = new NamegiverContext(Configuration))
     {
         return(Ok(await db.Names.AddName(name)));
     }
 }
Esempio n. 3
0
 public async Task <ActionResult <string> > GetNameInfoUrl(int id)
 {
     using (var db = new NamegiverContext(Configuration))
     {
         return(Ok(await db.Names.GetNameInfoUrl(id)));
     }
 }
Esempio n. 4
0
 public async Task <ActionResult <NameInfo> > GetRandomName()
 {
     using (var db = new NamegiverContext(Configuration))
     {
         return(Ok(await db.Names.GetRandomNameInfo()));
     }
 }
Esempio n. 5
0
 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();
     }
 }
Esempio n. 7
0
 public async Task <ActionResult> DeleteName(int id)
 {
     using (var db = new NamegiverContext(Configuration))
     {
         await db.Names.DeleteName(id);
     }
     return(NoContent());
 }
Esempio n. 8
0
 public CharacterModel(IConfiguration configuration)
 {
     context = new NamegiverContext(configuration);
 }