public async Task <IActionResult> Edit(int id, [Bind("EmploymentFormId,EmploymentFormName")] EmploymentForm employmentForm) { if (id != employmentForm.EmploymentFormId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employmentForm); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmploymentFormExists(employmentForm.EmploymentFormId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employmentForm)); }
public async Task <IActionResult> Create([Bind("EmploymentFormId,EmploymentFormName")] EmploymentForm employmentForm) { if (ModelState.IsValid) { _context.Add(employmentForm); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employmentForm)); }
/// <summary> /// Инициализация таблицы "Формы занятости" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateEmploymentForms(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <Microsoft.Extensions.DependencyInjection.IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Формы занятости" if (!await context.EmploymentForms.AnyAsync()) { EmploymentForm EmploymentForm1 = new EmploymentForm { EmploymentFormId = 1, EmploymentFormName = "основное" }; EmploymentForm EmploymentForm2 = new EmploymentForm { EmploymentFormId = 2, EmploymentFormName = "внутреннее совместительство" }; EmploymentForm EmploymentForm3 = new EmploymentForm { EmploymentFormId = 3, EmploymentFormName = "внешнее совместительство" }; EmploymentForm EmploymentForm4 = new EmploymentForm { EmploymentFormId = 4, EmploymentFormName = "работа по договору ГПХ" }; await context.EmploymentForms.AddRangeAsync( EmploymentForm1, EmploymentForm2, EmploymentForm3, EmploymentForm4 ); await context.SaveChangesAsync(); } #endregion } }