示例#1
0
 public Task UpdateAsync(User user)
 {
     db.Users.Attach(user);
     db.Entry(user).State = EntityState.Modified;
     db.Configuration.ValidateOnSaveEnabled = false;
     return(db.SaveChangesAsync());
 }
 public ActionResult Edit([Bind(Include = "ID,Name")] 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,Name")] Catergory catergory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(catergory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(catergory));
 }
示例#4
0
        public void Update(Author item)
        {
            var entity = db.Authors.Find(item.Id);

            if (entity == null)
            {
                return;
            }
            db.Entry(entity).CurrentValues.SetValues(item);
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "ID,Title,PublishedDate,Description,ISBN,CategotyID")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategotyID = new SelectList(db.Categories, "ID", "Name", book.CategotyID);
     return(View(book));
 }
示例#6
0
        public void Update(Book item)
        {
            var entity = db.Books.Find(item.Id);

            if (entity == null)
            {
                return;
            }

            var tags = item.Tags;

            entity.Tags = new List <Tag>();
            foreach (var booktag in tags)
            {
                Tag tag = db.Tags.SingleOrDefault(t => t.Name == booktag.Name);
                if (tag == null)
                {
                    tag = new Tag {
                        Name = booktag.Name
                    };
                    db.Tags.Add(tag);
                }
                entity.Tags.Add(tag);
            }

            var authors = item.Authors;

            entity.Authors = new List <Author>();
            foreach (var author in authors)
            {
                Author aut = db.Authors.SingleOrDefault(t => t.Name == author.Name);
                if (aut == null)
                {
                    continue;
                }
                entity.Authors.Add(aut);
            }
            db.Entry(entity).CurrentValues.SetValues(item);
        }