public async Task TemporalPointInTimeQueryAsync()
    {
        Book?book = await _booksContext.Books.FindAsync(1);

        if (book is null)
        {
            return;
        }
        // read shadow property for time
        if (_booksContext.Entry(book).CurrentValues["PeriodStart"] is DateTime periodStart)
        {
            DateTime previousTime = periodStart.AddSeconds(-4);
            var      previousBook = await _booksContext.Books
                                    .TemporalAsOf(previousTime)
                                    .TagWith("temporalasof")
                                    .SingleOrDefaultAsync(b => b.BookId == book.BookId);

            Console.WriteLine($"actual: {book.BookId}: {book.Title}, {book.Publisher}");
            if (previousBook is not null)
            {
                Console.WriteLine($"earlier: {previousBook.BookId}: {previousBook.Title}, " +
                                  $"{previousBook.Publisher}");
            }
        }
    }
示例#2
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todoItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> PutTitle([FromRoute] string id, [FromBody] Title title)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != title.Id)
            {
                return(BadRequest());
            }

            _context.Entry(title).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TitleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        public IHttpActionResult PutBook(int id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.Id)
            {
                return(BadRequest());
            }

            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#5
0
        public async Task <IActionResult> PutGenre(long id, Genre genre)
        {
            if (id != genre.Id)
            {
                return(BadRequest());
            }

            _context.Entry(genre).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GenreExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#6
0
        public async Task <IActionResult> PutMagazine(int id, Magazine magazine)
        {
            if (id != magazine.Id)
            {
                return(BadRequest());
            }

            _context.Entry(magazine).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MagazineExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IHttpActionResult> PutPublisher(int id, Publisher publisher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != publisher.PublisherId)
            {
                return(BadRequest());
            }

            db.Entry(publisher).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PublisherExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutAuthor([FromRoute] int id, [FromBody] Author author)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != author.ID)
            {
                return(BadRequest());
            }

            _context.Entry(author).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#9
0
        public async Task <IActionResult> PutPublisher(int id, Publisher publisher)
        {
            if (id != publisher.Id)
            {
                return(BadRequest());
            }

            _context.Entry(publisher).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PublisherExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#10
0
        public async Task <IActionResult> PutBook(int id, [FromBody] Book book)
        {
            if (id != book.BookId)
            {
                return(BadRequest());
            }

            _context.Entry(book).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#11
0
        public async Task <IActionResult> PutAuthors(long id, Authors authors)
        {
            if (id != authors.id)
            {
                return(BadRequest());
            }

            _context.Entry(authors).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#12
0
        // Login button logic
        private void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                var reader = context.Readers.ToList().Single(r => r.nickname == nicknameTextBox.Text); // Find current user
                context.Entry(reader).Reference(r => r.department).Load();
                if (PasswordManager.VerifyHashedPassword(reader.password, passwordTtextBox.Text))      // Check the password
                {
                    ReaderInfo.nicknameReader = reader.nickname;
                    if (reader.department != null)
                    {
                        ReaderInfo.departmentReader = reader.department.id;
                    }
                    ReaderInfo.score    = reader.receivedPoints - reader.spentPoints;
                    ReaderInfo.idReader = reader.id;


                    // Go to main form
                    MainForm mainForm = new MainForm();
                    mainForm.Show();
                    Hide();
                }
                else
                {
                    MessageBox.Show("Incorrect password", "Something went wrong :c");
                }
            }
            catch
            {
                MessageBox.Show("User with login " + nicknameTextBox.Text + " doesn't exist", "Something went wrong :c");
            }
        }
示例#13
0
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         booksContext.Entry(book).State = EntityState.Modified;
         booksContext.SaveChanges();
         return(RedirectToAction("AllTheBooks"));
     }
     return(View(book));
 }
 public ActionResult Edit([Bind(Include = "ID,au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
 public ActionResult Edit([Bind(Include = "Id,Title,Price")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
示例#16
0
 public ActionResult Edit([Bind(Include = "ID,stor_id,ord_num,ord_date,qty")] Sale sale)
 {
     if (ModelState.IsValid)
     {
         db.Entry(sale).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sale));
 }
示例#17
0
        public ActionResult Editar(Books book)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _booksContext.Entry(book).State = System.Data.EntityState.Modified;
                    _booksContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                throw;
            }


            return(View(book));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Title,Author")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Entry(book).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(book));
        }
示例#19
0
        // GET: Books
        public async Task <IActionResult> Index()
        {
            var books = await _context.Books.ToListAsync();

            foreach (var b in books)
            {
                _context.Entry(b).Reference(book => book.Author).Load();
            }

            return(View(books));
        }
        public async Task <IActionResult> PutFileItem(int id, BookItem book)
        {
            if (id != book.BookItemId)
            {
                return(BadRequest());
            }

            _context.Entry(book).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
示例#21
0
        public void Create(T entity)
        {
            var entry = _dbContext.Entry(entity);

            entry.State = EntityState.Added;

            DbSet.Add(entity);
        }
示例#22
0
        public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // book object Id must match url param Id
            if (id != book.BookId)
            {
                return(BadRequest());
            }

            var dbBook = await _context.Books.Select(b => new { b.BookId, b.UserId }).SingleOrDefaultAsync(b => b.BookId.Equals(id));

            // specfied book must exist
            if (dbBook == null)
            {
                return(NotFound());
            }

            // users can only update books belonging to themselves
            var currentUserId = int.Parse(User.Identity.Name);

            if ((dbBook.UserId != currentUserId || book.UserId != currentUserId) && !User.IsInRole(Role.Admin))
            {
                return(Forbid());
            }

            book.DateModified          = DateTime.Now;
            _context.Entry(book).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#23
0
        public ActionResult Edit([Bind(Include = "ID,ISBN,Titulo,FechaPublicacion,Cantidad,Editora,Cantidad,Cantidad_Paginas")] Libro libro, string[] selectedAuthors)
        {
            if (ModelState.IsValid)
            {
                db.Entry(libro).State = EntityState.Modified;

                updateSelectedAuthors(libro.ID, selectedAuthors);

                db.SaveChanges();
                //return RedirectToAction("Index");
                return(Content("<script>alert('Actualizado correctamente');\nwindow.location.href = \"/Libros\"</script>"));
            }
            ViewBag.Editora = new SelectList(db.Editoras, "ID", "Editorial", libro.Editora);
            return(View(libro));
        }
        public async void ExplicitLoadingSample()
        {
            var q = _booksContext.Books;  // 1 query für Bücher, proxy not needed

            foreach (var b in q)
            {
                Console.WriteLine($"{b.Title}");
                await _booksContext.Entry(b).Collection(b1 => b1.Chapters).LoadAsync(); // pro Buch 1 Query für Chapters

                foreach (var c in b.Chapters)
                {
                    Console.WriteLine($"\t{c.Title}");
                }
            }
        }
        public async Task <IActionResult> PutBookItem(long id, BookItem bookItem)
        {
            if (id != bookItem.Id)
            {
                return(BadRequest());
            }

            if (!BookItemExists(id))
            {
                return(NotFound());
            }

            _context.Entry(bookItem).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            return(Ok(bookItem));
        }
示例#26
0
    public async Task UpdateBookAsync()
    {
        Book?book = await _booksContext.Books.FindAsync(1);

        if (book != null)
        {
            // detach the existing object from the context which allows to attach it with the Update method
            _booksContext.Entry(book).State = EntityState.Detached;
            Book bookUpdate = book with {
                Title = "Professional C# and .NET - 2021 Edition"
            };
            _booksContext.Update(bookUpdate);
            int records = await _booksContext.SaveChangesAsync();

            Console.WriteLine($"{records} record updated");
        }
        Console.WriteLine();
    }
        public async Task <ActionResult <Books> > UpdateAvailability(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }

            var book = _context.BookLists.Find(id);

            if (book == null)
            {
                return(BadRequest());
            }

            if (book.copiesAvailable > book.totalCopies || book.copiesAvailable <= 0)
            {
                return(BadRequest());
            }

            try
            {
                if (book.copiesAvailable > 0)
                {
                    book.copiesAvailable      -= 1;
                    _context.Entry(book).State = EntityState.Modified;
                    //_context.Entry(books).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(UnprocessableEntity(book));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BooksExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(Ok(book));
        }
示例#28
0
 public ActionResult Edit([Bind(Include = "ID,title_id,title,type,pub_id,price,advance,royalty,ytd_sales,notes,pubdate")] Title singleTitle)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(singleTitle).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(singleTitle));
     }
     catch (Exception ex)
     {
         ViewBag.ErrorMessage   = "Edit Title Action: Error: " + ex.Message;
         ViewBag.InnerException = "Inner Exception: " + ex.InnerException;
         return(View("TitleError"));
     }
 }
示例#29
0
 public void Update(BooksModels book)
 {
     db.Entry(book).State = EntityState.Modified;
 }
示例#30
0
 public void Update(Book b)
 {
     _context.Entry(b).State = EntityState.Modified;
 }