コード例 #1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(DbSchema).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbSchemaExists(DbSchema.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            string[] RoleIds = Request.Form["roles"].ToString().Split(",");

            _context.User.Add(User);
            var UserRolesVar = _context.User.First();

            UserRolesVar.Roles = new List <UserRoles>();
            foreach (string ID in RoleIds)
            {
                UserRolesVar.Roles.Add(new UserRoles
                {
                    RoleID = _context.Role.Where(r => r.ID == Convert.ToInt32(ID))
                             .First().ID
                });
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Role.Add(Role);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
ファイル: Delete.cshtml.cs プロジェクト: Regis-1/AspNet
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GlobalDataBase = await _context.GlobalDataBase.FindAsync(id);

            if (GlobalDataBase != null)
            {
                _context.GlobalDataBase.Remove(GlobalDataBase);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
ファイル: Delete.cshtml.cs プロジェクト: helloyuzz/UWP.Core
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DbSchema = await _context.DbSchemas.FindAsync(id);

            if (DbSchema != null)
            {
                _context.DbSchemas.Remove(DbSchema);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            User = await _context.User.FindAsync(id);

            if (User != null)
            {
                _context.User.Remove(User);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
ファイル: DbSeeder.cs プロジェクト: learningman7777/WebApp
        public async Task SeedDatabase()
        {
            if (!_context.Teachers.Any())
            {
                List <Teacher> teachers = new List <Teacher>()
                {
                    new Teacher()
                    {
                        Name = "세종대왕", Class = "한글"
                    },
                    new Teacher()
                    {
                        Name = "이순신", Class = "해상전략"
                    },
                    new Teacher()
                    {
                        Name = "제갈량", Class = "지략"
                    },
                    new Teacher()
                    {
                        Name = "을지문덕", Class = "지상전략"
                    },
                };

                await _context.AddRangeAsync(teachers);

                await _context.SaveChangesAsync();
            }

            var adminAccount = await _userManager.FindByNameAsync("*****@*****.**");

            var adminRole = new IdentityRole("Admin");
            await _roleManager.CreateAsync(adminRole);

            await _userManager.AddToRoleAsync(adminAccount, adminRole.Name);
        }