Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,Id,AddedDate")] Author author)
        {
            if (id != author.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(author);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorExists(author.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
        public async Task <IActionResult> Edit(int id, Book book)
        {
            if (id != book.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var path = UploadImage(book.Image);
                book.ImagePath = string.IsNullOrWhiteSpace(path) ? book.ImagePath : path;

                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(_context.Books.Any(e => e.Id == id) ?
                           View(book) : NotFound());
                }
            }
            return(View(book));
        }
Example #3
0
        public bool Update(TEntity entity)
        {
            try
            {
                _context.Update(entity);

                _context.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, BookViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var imageName = string.Empty;
                    if (model.BookImage != null && model.BookImage.Length > 0)
                    {
                        imageName = model.BookImage.FileName;
                        var fullPath = Path.Combine(_webHostEnvironment.WebRootPath, "uploads", imageName);
                        using var stream = new FileStream(fullPath, FileMode.Create);
                        model.BookImage.CopyTo(stream);
                    }

                    var book = new Book
                    {
                        Id          = model.Id,
                        Title       = model.Title,
                        Discription = model.Discription,
                        AuthorId    = model.AuthorId,
                        ImagePath   = string.IsNullOrWhiteSpace(imageName) ? model.ImagePath : imageName
                    };

                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch
                {
                    return(RedirectToAction(nameof(Edit)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Edit)));
        }
Example #5
0
 public void update(int id, Author newAuthor)
 {
     db.Update(newAuthor);
     db.SaveChanges();
 }
 public void update(int id, Book newBook)
 {
     db.Update(newBook);
     db.SaveChanges();
 }
Example #7
0
 public void update(int id, Auther newAuther)
 {
     db.Update(newAuther);
     save();
 }
Example #8
0
 public void Update(int id, Author newAuthor)
 {
     _db.Update(newAuthor);
     _db.SaveChanges();
 }
 public void update(int id, Book newBook)
 {
     db.Update(newBook);
     save();
 }
Example #10
0
 public void Update(int id, Book newBook)
 {
     _db.Update(newBook);
     _db.SaveChanges();
 }