public async Task <IActionResult> Edit(int id, [Bind("AcademicDegreeGroupId,AcademicDegreeGroupName")] AcademicDegreeGroup academicDegreeGroup)
        {
            if (id != academicDegreeGroup.AcademicDegreeGroupId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(academicDegreeGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AcademicDegreeGroupExists(academicDegreeGroup.AcademicDegreeGroupId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(academicDegreeGroup));
        }
        public async Task <IActionResult> Create([Bind("AcademicDegreeGroupId,AcademicDegreeGroupName")] AcademicDegreeGroup academicDegreeGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(academicDegreeGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(academicDegreeGroup));
        }
Beispiel #3
0
        /// <summary>
        /// Инициализация таблиц, связанных с пользователем
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateUserData(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Группы ученых степеней"
                if (!await context.AcademicDegreeGroups.AnyAsync())
                {
                    AcademicDegreeGroup AcademicDegreeGroup1 = new AcademicDegreeGroup
                    {
                        AcademicDegreeGroupId   = 1,
                        AcademicDegreeGroupName = "Кандидаты наук"
                    };

                    AcademicDegreeGroup AcademicDegreeGroup2 = new AcademicDegreeGroup
                    {
                        AcademicDegreeGroupId   = 2,
                        AcademicDegreeGroupName = "Доктора наук"
                    };

                    await context.AcademicDegreeGroups.AddRangeAsync(
                        AcademicDegreeGroup1,
                        AcademicDegreeGroup2
                        );

                    await context.SaveChangesAsync();
                }
                #endregion

                #region Инициализация таблицы "Ученые степени"
                if (!await context.AcademicDegrees.AnyAsync())
                {
                    AcademicDegree AcademicDegree1 = new AcademicDegree
                    {
                        AcademicDegreeId      = 1,
                        AcademicDegreeGroupId = 1,
                        AcademicDegreeName    = "Кандидат технических наук"
                    };

                    AcademicDegree AcademicDegree2 = new AcademicDegree
                    {
                        AcademicDegreeId      = 2,
                        AcademicDegreeGroupId = 1,
                        AcademicDegreeName    = "Кандидат сельскохозяйственных наук"
                    };

                    AcademicDegree AcademicDegree3 = new AcademicDegree
                    {
                        AcademicDegreeId      = 3,
                        AcademicDegreeGroupId = 2,
                        AcademicDegreeName    = "Доктор технических наук"
                    };

                    AcademicDegree AcademicDegree4 = new AcademicDegree
                    {
                        AcademicDegreeId      = 4,
                        AcademicDegreeGroupId = 2,
                        AcademicDegreeName    = "Доктор сельскохозяйственных наук"
                    };

                    await context.AcademicDegrees.AddRangeAsync(
                        AcademicDegree1,
                        AcademicDegree2,
                        AcademicDegree3,
                        AcademicDegree4
                        );

                    await context.SaveChangesAsync();
                }
                #endregion

                #region Инициализация таблицы "Ученые звания"
                if (!await context.AcademicStats.AnyAsync())
                {
                    AcademicStat AcademicStat1 = new AcademicStat
                    {
                        AcademicStatId   = 1,
                        AcademicStatName = "Доцент"
                    };

                    AcademicStat AcademicStat2 = new AcademicStat
                    {
                        AcademicStatId   = 2,
                        AcademicStatName = "Профессор"
                    };

                    await context.AcademicStats.AddRangeAsync(
                        AcademicStat1,
                        AcademicStat2
                        );

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }