public void Put(int id, [FromBody] Author itemNew)
        {
            BookStoreDataContext db = new BookStoreDataContext();
            var item = db.Authors.SingleOrDefault(p => p.AuthorID.Equals(id));

            item.Name = itemNew.Name;

            db.Update(item);
            db.SaveChangesAsync();
        }
        public IActionResult Edit([Bind("RoleID,RoleName")] Role item)
        {
            if (ModelState.IsValid)
            {
                db.Update(item);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Beispiel #3
0
        public IActionResult Edit([Bind("AuthorID,Name, Email")] Author item)
        {
            if (ModelState.IsValid)
            {
                db.Update(item);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
        public void Put(int id, [FromBody] Book itemNew)
        {
            BookStoreDataContext db = new BookStoreDataContext();
            var item = db.Books.SingleOrDefault(p => p.ISBN.Equals(id));

            item.CategoryID  = itemNew.CategoryID;
            item.Title       = itemNew.Title;
            item.Photo       = itemNew.Photo;
            item.PublishDate = itemNew.PublishDate;
            item.Price       = itemNew.Price;
            item.Quantity    = itemNew.Quantity;

            db.Update(item);
            db.SaveChangesAsync();
        }
        public IActionResult Edit([Bind("ISBN, CategoryID, Title, Photo, PublishDate, Price, Quantity, AuthorIDs")] BookFormViewModel item)
        {
            ViewBag.Categories = new SelectList(db.Categories.ToList(), "CategoryID", "Name");
            ViewBag.Authors    = new MultiSelectList(db.Authors.ToList(), "AuthorID", "Name");

            if (ModelState.IsValid)
            {
                db.BooksAuthors.RemoveRange(db.BooksAuthors.Where(p => p.ISBN.Equals(item.ISBN)));
                db.SaveChanges();

                Book book = db.Books.SingleOrDefault(p => p.ISBN.Equals(item.ISBN));
                book.CategoryID  = item.CategoryID;
                book.Title       = item.Title;
                book.PublishDate = item.PublishDate;
                book.Price       = item.Price;
                book.Quantity    = item.Quantity;
                db.Update(book);

                foreach (int authorId in item.AuthorIDs)
                {
                    BookAuthor bookAuthor = new BookAuthor();
                    bookAuthor.ISBN     = item.ISBN;
                    bookAuthor.AuthorID = authorId;
                    db.Add(bookAuthor);
                }

                db.SaveChanges();

                if (item.Photo != null)
                {
                    var file    = item.Photo;
                    var uploads = Path.Combine(_environment.WebRootPath, "upload");
                    if (file.Length > 0)
                    {
                        using (var fileStream = new FileStream(Path.Combine(uploads, item.ISBN + ".jpg"), FileMode.Create)){
                            file.CopyToAsync(fileStream);
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Beispiel #6
0
        public IActionResult Edit([Bind("UserName, RoleID, Email, Password, PasswordConfirm, Fullname")] UserEditFormViewModel item)
        {
            ViewBag.Roles = new SelectList(db.Roles.ToList(), "RoleID", "RoleName");

            if (ModelState.IsValid)
            {
                User user = db.Users.SingleOrDefault(p => p.UserName.Equals(item.UserName));
                user.UserName = item.UserName;
                user.RoleID   = item.RoleID;
                user.Email    = item.Email;
                if (!String.IsNullOrEmpty(item.Password))
                {
                    user.Password = EncryptString(item.Password, key);
                }
                user.Fullname = item.Fullname;

                db.Update(user);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View());
        }