public async Task <IActionResult> Edit(int id, [Bind("UchPosobieAuthorId,AuthorId,UchPosobieId")] UchPosobieAuthor uchPosobieAuthor) { if (id != uchPosobieAuthor.UchPosobieAuthorId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(uchPosobieAuthor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UchPosobieAuthorExists(uchPosobieAuthor.UchPosobieAuthorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Author, "AuthorId", "AuthorId", uchPosobieAuthor.AuthorId); ViewData["UchPosobieId"] = new SelectList(_context.UchPosobie, "UchPosobieId", "UchPosobieId", uchPosobieAuthor.UchPosobieId); return(View(uchPosobieAuthor)); }
/// <summary> /// Добавление / редактирование автора учебного пособия /// </summary> /// <param name="id"></param> /// <param name="UchPosobieAuthorId"></param> /// <returns></returns> public async Task <IActionResult> UchPosobieAuthorCreateOrEdit(int UchPosobieId, int UchPosobieAuthorId) { // Находим учебное пособие по УИД var uchPosobie = await _uchPosobiyaRepository.GetUchPosobieByIdAsync(UchPosobieId); if (uchPosobie == null || uchPosobie.UchPosobieId == 0) { return(NotFound()); } var uchPosobieAuthor = new UchPosobieAuthor(); uchPosobieAuthor.UchPosobie = uchPosobie; // Если UchPosobieAuthorId=0 - новая запись // иначе - редактирование if (UchPosobieAuthorId != 0) { uchPosobieAuthor = uchPosobie.UchPosobieAuthors.SingleOrDefault(ua => ua.UchPosobieAuthorId == UchPosobieAuthorId); if (uchPosobieAuthor == null) { return(NotFound()); } } ViewBag.Authors = _selectListRepository.GetSelectListAuthors(); return(View(uchPosobieAuthor)); }
public async Task <IActionResult> Create([Bind("UchPosobieAuthorId,AuthorId,UchPosobieId")] UchPosobieAuthor uchPosobieAuthor) { if (ModelState.IsValid) { _context.Add(uchPosobieAuthor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Author, "AuthorId", "AuthorName", uchPosobieAuthor.AuthorId); ViewData["UchPosobieId"] = new SelectList(_context.UchPosobie, "UchPosobieId", "UchPosobieName", uchPosobieAuthor.UchPosobieId); return(View(uchPosobieAuthor)); }
public async Task <IActionResult> UchPosobieAuthorCreateOrEdit(UchPosobieAuthor uchPosobieAuthor) { if (uchPosobieAuthor == null) { return(NotFound()); } if (uchPosobieAuthor.AuthorId == 0) { return(RedirectToAction(nameof(AddAuthor), new { uchPosobieAuthor.UchPosobieId, uchPosobieAuthor.UchPosobieAuthorId })); } else { await _uchPosobiyaRepository.UpdateUchPosobieAuthorAsync(uchPosobieAuthor); } return(RedirectToAction(nameof(Index))); }
/// <summary> /// Добавление автора в справочник /// </summary> /// <returns></returns> public async Task <IActionResult> AddAuthor(UchPosobieAuthor uchPosobieAuthor, string fio, string selectedAppUserId) { if (!string.IsNullOrWhiteSpace(selectedAppUserId)) { Author author = await _uchPosobiyaRepository.CreateAuthorByAppUserIdAsync(selectedAppUserId); uchPosobieAuthor.AuthorId = author.AuthorId; await _uchPosobiyaRepository.UpdateUchPosobieAuthorAsync(uchPosobieAuthor); return(RedirectToAction(nameof(Index))); } if (!string.IsNullOrWhiteSpace(fio)) { ViewBag.FindedUsers = _selectListRepository.GetSelectListAppUsersByFirstName(fio); } ViewBag.fio = fio; return(View(uchPosobieAuthor)); }