Beispiel #1
0
        /// <summary>
        /// Инициализация данных, связанных с численность обучающихся
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task CreateEduChislen(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>();

                #region Инициализация таблицы "Численность обучающихся"
                if (!await context.EduChislens.AnyAsync())
                {
                    foreach (var profile in context.EduProfiles)
                    {
                        foreach (var form in context.EduForms)
                        {
                            EduChislen eduChislen = new EduChislen();
                            eduChislen.EduProfileId = profile.EduProfileId;
                            eduChislen.EduFormId    = form.EduFormId;

                            await context.EduChislens.AddAsync(eduChislen);
                        }
                    }

                    await context.SaveChangesAsync();
                }
                #endregion
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("EduChislenId,NumberBFpriem,NumberBRpriem,NumberBMpriem,NumberPpriem,EduFormId,EduProfileId,NumberInostr")] EduChislen eduChislen)
        {
            if (id != eduChislen.EduChislenId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eduChislen);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EduChislenExists(eduChislen.EduChislenId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EduFormId"]    = new SelectList(_context.EduForms, "EduFormId", "EduFormId", eduChislen.EduFormId);
            ViewData["EduProfileId"] = new SelectList(_context.EduProfiles, "EduProfileId", "EduProfileId", eduChislen.EduProfileId);
            return(View(eduChislen));
        }
        public async Task <IActionResult> Create([Bind("EduChislenId,NumberBFpriem,NumberBRpriem,NumberBMpriem,NumberPpriem,EduFormId,EduProfileId,NumberInostr")] EduChislen eduChislen)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eduChislen);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EduFormId"]    = new SelectList(_context.EduForms, "EduFormId", "EduFormId", eduChislen.EduFormId);
            ViewData["EduProfileId"] = new SelectList(_context.EduProfiles, "EduProfileId", "EduProfileId", eduChislen.EduProfileId);
            return(View(eduChislen));
        }