Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("EduProgramPodgId,EduProgramPodgName")] EduProgramPodg eduProgramPodg)
        {
            if (id != eduProgramPodg.EduProgramPodgId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eduProgramPodg);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EduProgramPodgExists(eduProgramPodg.EduProgramPodgId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(eduProgramPodg));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("EduProgramPodgId,EduProgramPodgName")] EduProgramPodg eduProgramPodg)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eduProgramPodg);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(eduProgramPodg));
        }
        /// <summary>
        /// Инициализация таблицы "Программы подготовки"
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateEduProgramPodg(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Программы подготовки"
                if (!await context.EduProgramPodg.AnyAsync())
                {
                    EduProgramPodg EduProgramPodg1 = new EduProgramPodg
                    {
                        EduProgramPodgId   = 1,
                        EduProgramPodgName = "Академический бакалавриат"
                    };

                    EduProgramPodg EduProgramPodg2 = new EduProgramPodg
                    {
                        EduProgramPodgId   = 2,
                        EduProgramPodgName = "Прикладной бакалавриат"
                    };

                    EduProgramPodg EduProgramPodg3 = new EduProgramPodg
                    {
                        EduProgramPodgId   = 3,
                        EduProgramPodgName = "Академическая магистратура"
                    };

                    EduProgramPodg EduProgramPodg4 = new EduProgramPodg
                    {
                        EduProgramPodgId   = 4,
                        EduProgramPodgName = "Прикладная магистратура"
                    };

                    EduProgramPodg EduProgramPodg5 = new EduProgramPodg
                    {
                        EduProgramPodgId   = 5,
                        EduProgramPodgName = "Нет"
                    };

                    await context.EduProgramPodg.AddRangeAsync(
                        EduProgramPodg1,
                        EduProgramPodg2,
                        EduProgramPodg3,
                        EduProgramPodg4,
                        EduProgramPodg5
                        );

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