Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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);
        }