Пример #1
0
        public async Task <PhoneBook> AddPhonebook(PhoneBook phoneBook)
        {
            _db.PhoneBook.Add(phoneBook);
            await _db.SaveChangesAsync();

            return(phoneBook);
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        public async Task <TEntity> Add(TEntity t)
        {
            _db.Set <TEntity>().Add(t);
            await _db.SaveChangesAsync();

            return(t);
        }
Пример #7
0
        public async Task <T> AddAsync(T entity)
        {
            _dbContext.Set <T>().Add(entity);
            await _dbContext.SaveChangesAsync();

            return(entity);
        }
Пример #8
0
        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)));
        }
Пример #9
0
        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);
        }