public async Task <PhoneBook> AddPhonebook(PhoneBook phoneBook) { _db.PhoneBook.Add(phoneBook); await _db.SaveChangesAsync(); return(phoneBook); }
public async Task <IActionResult> PutContact(int id, Contact contact) { if (id != contact.Id) { return(BadRequest()); } _context.Entry(contact).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPhonebook(long id, Phonebook phonebook) { if (id != phonebook.Id) { return(BadRequest()); } _context.Entry(phonebook).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhonebookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("ID,Name")] PhoneBook phoneBook) { if (ModelState.IsValid) { _context.Add(phoneBook); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(phoneBook)); }
public async Task <IActionResult> Create([Bind("Id,PersonnelNumber,Name,Position,Department,LocalPhoneNumber,CityPhoneNumber,Mail,Room")] BookEntry bookEntry) { if (!VerifyPersonnelNumber(bookEntry)) { ModelState.AddModelError(nameof(bookEntry.PersonnelNumber), "Табельный номер уже существует"); } if (ModelState.IsValid) { _context.Add(bookEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bookEntry)); }
public async Task <TEntity> Add(TEntity t) { _db.Set <TEntity>().Add(t); await _db.SaveChangesAsync(); return(t); }
public async Task <T> AddAsync(T entity) { _dbContext.Set <T>().Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task <IActionResult> DeleteConfirmed(int id) { var phoneBookEntry = await _context.PhoneBookEntry.FindAsync(id); _context.PhoneBookEntry.Remove(phoneBookEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), nameof(PhoneBookController))); }
public bool CreateContact(Entry newEntry, int phonebookId) { _phonebookContext.ChangeTracker.LazyLoadingEnabled = false; _phonebookContext.Entries.Add(newEntry); _phonebookContext.SaveChanges(); var phonebookEntry = new PhoneBookEntries { entry_id = newEntry.Id, Phonebook_id = phonebookId }; _phonebookContext.PhoneBookEntries.Add(phonebookEntry); _phonebookContext.SaveChangesAsync(); return(true); }