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