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 PhonebookContext GetPhonebookContext() { var options = new DbContextOptionsBuilder <PhonebookContext>() .UseInMemoryDatabase(databaseName: "InMemoryPhonebookDatabase") .Options; var dbContext = new PhonebookContext(options); var userLogin = new UserLogin() { Username = "******", Password = "******", EmailAddress = "*****@*****.**" }; dbContext.Add(userLogin); dbContext.SaveChanges(); return(dbContext); }