public async Task <IActionResult> Edit(int id, [Bind("UchPosobieFormaIzdaniyaId,UchPosobieFormaIzdaniyaName")] UchPosobieFormaIzdaniya uchPosobieFormaIzdaniya) { if (id != uchPosobieFormaIzdaniya.UchPosobieFormaIzdaniyaId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(uchPosobieFormaIzdaniya); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UchPosobieFormaIzdaniyaExists(uchPosobieFormaIzdaniya.UchPosobieFormaIzdaniyaId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(uchPosobieFormaIzdaniya)); }
/// <summary> /// Инициализация таблицы "Форма издания учебного пособия" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateUchPosobieFormaIzdaniya(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Форма издания учебного пособия" if (!await context.UchPosobieFormaIzdaniya.AnyAsync()) { UchPosobieFormaIzdaniya UchPosobieFormaIzdaniyaName1 = new UchPosobieFormaIzdaniya { UchPosobieFormaIzdaniyaId = 1, UchPosobieFormaIzdaniyaName = "Печатная", }; UchPosobieFormaIzdaniya UchPosobieFormaIzdaniyaName2 = new UchPosobieFormaIzdaniya { UchPosobieFormaIzdaniyaId = 2, UchPosobieFormaIzdaniyaName = "Электронная", }; await context.UchPosobieFormaIzdaniya.AddRangeAsync( UchPosobieFormaIzdaniyaName1, UchPosobieFormaIzdaniyaName2 ); await context.SaveChangesAsync(); } #endregion } }
public async Task <IActionResult> Create([Bind("UchPosobieFormaIzdaniyaId,UchPosobieFormaIzdaniyaName")] UchPosobieFormaIzdaniya uchPosobieFormaIzdaniya) { if (ModelState.IsValid) { _context.Add(uchPosobieFormaIzdaniya); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(uchPosobieFormaIzdaniya)); }