public async Task <bool> UpdateBreedAsync(BreedEntity breedEntity)
        {
            var breedToUpdate = await _dbContext.Breeds.FirstOrDefaultAsync(c => c.Id == breedEntity.Id);

            _dbContext.Entry(breedToUpdate).CurrentValues.SetValues(breedEntity);
            return(true);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutBorrowing(int borrowerid, int inventoryid, Borrowing borrowing)
        {
            if (borrowerid != borrowing.BorrowerID || inventoryid != borrowing.InventoryID || !ModelState.IsValid)
            {
                return(BadRequest(ModelState.SelectMany(x => x.Value.Errors)));
            }

            _context.Entry(borrowing).State = EntityState.Modified;
            InventoryItem item = await _context.InventoryItems.FirstOrDefaultAsync(i => i.InventoryID == inventoryid);

            try
            {
                if (borrowing.ReturnDate != null) //I de allra flesta fall är nu boken återlämnad.
                {
                    item.Available = true;        //Skulle väl vara i ev. klientprogrammet som säkerheten gällande returdatum ska skötas?
                }
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BorrowingExists(inventoryid, borrowerid))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutBorrower(int id, Borrower borrower)
        {
            if (id != borrower.BorrowerID || !ModelState.IsValid)
            {
                return(BadRequest(ModelState.SelectMany(x => x.Value.Errors)));
            }

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

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

            return(NoContent());
        }
Exemplo n.º 4
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (Context.Entry(entityToDelete).State == EntityState.Detached)
     {
         DbSet.Attach(entityToDelete);
     }
     DbSet.Remove(entityToDelete);
 }
Exemplo n.º 5
0
 /*
  * public MovieEntity CreateMovie(MovieEntity movie)
  * {
  *  int newId;
  *  var lastMovie = movies.OrderByDescending(s => s.Id).FirstOrDefault();
  *  {
  *      newId = lastMovie.Id + 1;
  *  }
  *  movie.Id = newId;
  *  movies.Add(movie);
  *  return movie;
  * }*/
 public void CreateMovie(MovieEntity movie)
 {
     //_dbContext.Entry(movie.Production).State = EntityState.Unchanged;
     if (movie.Production != null)
     {
         _dbContext.Entry(movie.Production).State = EntityState.Unchanged;
     }
     _dbContext.Movies.Add(movie);
 }
Exemplo n.º 6
0
        public void CreateHero(HeroEntity heroEntity)
        {
            if (heroEntity.Breed != null)
            {
                _dbContext.Entry(heroEntity.Breed).State = EntityState.Unchanged;
            }

            _dbContext.Heroes.Add(heroEntity);
        }
Exemplo n.º 7
0
 public void CreateBook(BookEntity book)
 {
     /**var latestBook = books.OrderByDescending(b => b.Id).FirstOrDefault();
      * var nextBookId = latestBook == null ? 1 : latestBook.Id + 1;
      * book.Id = nextBookId;
      * books.Add(book);
      * return book;*/
     libraryDbContext.Entry(book.Author).State = EntityState.Unchanged;
     libraryDbContext.Books.Add(book);
 }
Exemplo n.º 8
0
        public ActionResult BooksUpdate([DataSourceRequest] DataSourceRequest request, BookViewModel book)
        {
            if (ModelState.IsValid)
            {
                var db = new LibraryDbContext();

                var category = db.Categories.FirstOrDefault(x => x.Name == book.CategoryName);

                var oldBook = db.Books.Single(x => x.Id == book.Id);

                if (oldBook.Category.Name != book.CategoryName)
                {
                    oldBook.Category = category;
                    UpdateBookFields(book, oldBook);
                    category.Books.Add(oldBook);

                    db.SaveChanges();
                }
                else
                {
                    UpdateBookFields(book, oldBook);

                    db.Entry(oldBook).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(Json(new[] { book }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PutLibraryAssett([FromRoute] int id, [FromBody] LibraryAsset libraryAssett)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public IHttpActionResult PutMember(int id, Member member)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != member.MemberId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 11
0
 public void Update(T entity)
 {
     _context.Entry(entity).State = EntityState.Modified;
     _context.Attach(entity);
     _context.Update(entity);
     Save();
 }
Exemplo n.º 12
0
        public async Task <IActionResult> PutBookAuthor(int authorid, string isbn, BookAuthor bookAuthor)
        {
            if (authorid != bookAuthor.AuthorID || isbn != bookAuthor.ISBN || !ModelState.IsValid)
            {
                return(BadRequest(ModelState.SelectMany(x => x.Value.Errors)));
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookAuthorExists(authorid, isbn))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] Book book)
        {
            if (id != book.IdBook)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 14
0
        public async Task <IActionResult> PutBook(int id, BookDTO book)
        {
            if (id != book.Id)
            {
                return(BadRequest());
            }

            var b = _bookServices.EditBook(id, book);

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

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

            return(NoContent());
        }
Exemplo n.º 15
0
        void IRepositorry.IRepository <Book> .Update(Book entity)
        {
            var entry = db.Entry(entity);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Exemplo n.º 16
0
        public bool UpdateCompany(CompanyEntity companyModel)
        {
            var companyToUpdate = _dbContext.Companies.FirstOrDefault(c => c.Id == companyModel.Id);

            _dbContext.Entry(companyToUpdate).CurrentValues.SetValues(companyModel);

            /*if (companyModel.Name != null)
             * {
             *  _dbContext.Entry(companyModel).Property(p => p.Name).IsModified = true;
             * }*/

            /*companyToUpdate.CEO = companyModel.CEO ?? companyToUpdate.CEO;
             * companyToUpdate.Country = companyModel.Country ?? companyToUpdate.Country;
             * companyToUpdate.FundationDate = companyModel.FundationDate ?? companyToUpdate.FundationDate;
             * companyToUpdate.Name = companyModel.Name ?? companyToUpdate.Name;*/
            return(true);
        }
Exemplo n.º 17
0
        public Book Update(Book entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var existing = _context.Books.FirstOrDefault(b => b.Id == entity.Id);

            if (existing != null)
            {
                _context.Entry(existing).CurrentValues.SetValues(entity);
                _context.Entry(existing).Property("AddedDate").IsModified = false;
            }
            _context.SaveChanges();
            return(existing);
        }
Exemplo n.º 18
0
 //Book Delete Database//
 public void Delete(Book book)
 {
     using (LibraryDbContext _context = new LibraryDbContext())
     {
         var entity = _context.Entry(book);
         entity.State = EntityState.Deleted;
         _context.SaveChanges();
     }
 }
 //Delete Customer Databse//
 public void Delete(Customer customer)
 {
     using (LibraryDbContext _context = new LibraryDbContext())
     {
         var entity = _context.Entry(customer);
         entity.State = EntityState.Deleted;
         _context.SaveChanges();
     }
 }
Exemplo n.º 20
0
 //Orders Update Database//
 public void Update(Orders orders)
 {
     using (LibraryDbContext _context = new LibraryDbContext())
     {
         var entity = _context.Entry(orders);
         entity.State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
 //Manager Update Database//
 public void Update(Manager manager)
 {
     using (LibraryDbContext _context = new LibraryDbContext())
     {
         var entity = _context.Entry(manager);
         entity.State = EntityState.Modified;
         _context.SaveChanges();
     }
 }
Exemplo n.º 22
0
 public ActionResult EditBook(Book book)
 {
     if (book == null || !database.Books.Contains(book))
     {
         return(HttpNotFound());
     }
     database.Entry(book).State = EntityState.Modified;
     database.SaveChanges();
     return(PartialView("Partial", database.Books.ToList()));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "BookId,BookName,Status,BookCategory,BookAuthor")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Exemplo n.º 24
0
 public ActionResult Edit([Bind(Include = "Id,GenreName")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
Exemplo n.º 25
0
 public ActionResult Edit([Bind(Include = "BookId,Title,Author,Genre,Format,YearPublished")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Exemplo n.º 26
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,UserName")] Writer writer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(writer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(writer));
 }
Exemplo n.º 27
0
 public ActionResult Edit([Bind(Include = "MemberId,MemberName,Status,Age,Gender")] Member member)
 {
     if (ModelState.IsValid)
     {
         db.Entry(member).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(member));
 }
Exemplo n.º 28
0
 public ActionResult Edit([Bind(Include = "Id,Name,Url")] Pictures pictures)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pictures).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pictures));
 }
Exemplo n.º 29
0
        public ActionResult Put(int id, Book book)
        {
            if (id != book.Id)
            {
                return(BadRequest());
            }

            _db.Entry(book).State = EntityState.Modified;
            _db.SaveChanges();

            return(CreatedAtAction(nameof(Get), new { id = book.Id }, book));
        }
Exemplo n.º 30
0
 public ActionResult Edit([Bind(Include = "BookIssueId,MemberId,BookId,DateOfIssue,Status")] BookIssue bookIssue)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookIssue).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookId   = new SelectList(db.Books, "BookId", "BookName", bookIssue.BookId);
     ViewBag.MemberId = new SelectList(db.Members, "MemberId", "MemberName", bookIssue.MemberId);
     return(View(bookIssue));
 }
Exemplo n.º 31
0
        public ActionResult CategoriesUpdate([DataSourceRequest]DataSourceRequest request, CategoryViewModel category)
        {
            if (ModelState.IsValid)
            {
                var db = new LibraryDbContext();

                var newCategory = new Category()
                {
                    Id = category.Id,
                    Name = category.Name
                };
                db.Categories.Attach(newCategory);
                db.Entry(newCategory).State = EntityState.Modified;
                db.SaveChanges();
                
            }
            return Json(new[] { category }.ToDataSourceResult(request, ModelState));
        }
Exemplo n.º 32
0
        public ActionResult BooksUpdate([DataSourceRequest]DataSourceRequest request, BookViewModel book)
        {
            if (ModelState.IsValid)
            {
                var db = new LibraryDbContext();

                var category = db.Categories.FirstOrDefault(x => x.Name == book.CategoryName);

                var oldBook = db.Books.Single(x => x.Id == book.Id);
                
                if (oldBook.Category.Name != book.CategoryName)
                {
                    
                    oldBook.Category = category;
                    UpdateBookFields(book, oldBook);
                    category.Books.Add(oldBook);
                    
                    db.SaveChanges();
                }
                else
                {
                    UpdateBookFields(book, oldBook);
                    
                    db.Entry(oldBook).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return Json(new[] { book }.ToDataSourceResult(request, ModelState));
        }