Exemple #1
0
        public async Task <ActionResult> Edit(BookPicture bookPicture)
        {
            if (ModelState.IsValid)
            {
                bookPicture.TrackingState = TrackingState.Modified;
                try{
                    this.bookPictureService.Update(bookPicture);

                    var result = await this.unitOfWork.SaveChangesAsync();

                    return(Json(new { success = true, result = result }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { success = false, err = e.GetMessage() }, JsonRequestBehavior.AllowGet));
                }

                //DisplaySuccessMessage("Has update a BookPicture record");
                //return RedirectToAction("Index");
            }
            else
            {
                var modelStateErrors = string.Join(",", this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors.Select(n => n.ErrorMessage)));
                return(Json(new { success = false, err = modelStateErrors }, JsonRequestBehavior.AllowGet));
                //DisplayErrorMessage(modelStateErrors);
            }
            //var bookRepository = this.unitOfWork.RepositoryAsync<Book>();
            //return View(bookPicture);
        }
Exemple #2
0
        public async Task <ActionResult> Create(BookPicture bookPicture)
        {
            if (ModelState.IsValid)
            {
                try{
                    this.bookPictureService.Insert(bookPicture);
                    var result = await this.unitOfWork.SaveChangesAsync();

                    return(Json(new { success = true, result }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    return(Json(new { success = false, err = e.GetMessage() }, JsonRequestBehavior.AllowGet));
                }
                //DisplaySuccessMessage("Has update a bookPicture record");
            }
            else
            {
                var modelStateErrors = string.Join(",", this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors.Select(n => n.ErrorMessage)));
                return(Json(new { success = false, err = modelStateErrors }, JsonRequestBehavior.AllowGet));
                //DisplayErrorMessage(modelStateErrors);
            }
            //var bookRepository = this.unitOfWork.RepositoryAsync<Book>();
            //ViewBag.BookId = new SelectList(await bookRepository.Queryable().OrderBy(n=>n.Title).ToListAsync(), "Id", "Title", bookPicture.BookId);
            //return View(bookPicture);
        }
Exemple #3
0
        //GET: BookPictures/Create
        public ActionResult Create()
        {
            var bookPicture = new BookPicture();
            //set default value
            var bookRepository = this.unitOfWork.RepositoryAsync <Book>();

            ViewBag.BookId = new SelectList(bookRepository.Queryable().OrderBy(n => n.Title), "Id", "Title");
            return(View(bookPicture));
        }
        public async Task <IActionResult> Update(int id, BookUpdateViewModel viewModel)
        {
            if (!await _sessionService.IsAuthentificateAsync())
            {
                return(RedirectToAction("Login", "Library"));
            }
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var book = await _bookService.GetAsync(id);

            if (book == null || book.LibraryId != _sessionService.GetCurrentLibraryId())
            {
                ViewData["exist"] = false;
                return(View());
            }

            var model = _mapper.Map(viewModel, book);

            _db.Books.Update(model);
            if (viewModel.File != null)
            {
                var image = new BookPicture
                {
                    BookId   = book.Id,
                    FullPath = _fileService.SaveFile(viewModel.File),
                    Size     = viewModel.File.Length
                };
                _db.Add(image);
            }

            await _db.SaveChangesAsync();

            ViewData["exist"]   = true;
            TempData["updated"] = true;
            return(View(viewModel));
        }
Exemple #5
0
        private void LoadBooks(SDCContext db, UserProfile profile, Shelf shelf)
        {
            int perShelf   = _rnd.Next(10, 50);
            int startindex = Progress;

            for (int i = startindex; i < startindex + perShelf && Progress < _max; i++)
            {
                string isbn, title, author, publisher, imgurl;
                int    year;
                try {
                    isbn      = _booksSplit[i, 0];
                    title     = _booksSplit[i, 1];
                    author    = _booksSplit[i, 2];
                    year      = Int32.Parse(_booksSplit[i, 3]);
                    publisher = _booksSplit[i, 4];
                    imgurl    = _booksSplit[i, 5];
                }catch (Exception)
                {
                    continue;
                }

                DateTime d1 = DateTime.Now;
                Author   a  = null;
                if (!_authorsSet.ContainsKey(author))
                {
                    a = new Author()
                    {
                        Name           = author,
                        AddedDate      = DateTime.Now,
                        AddedBy        = profile,
                        LastModifiedBy = profile,
                        IsVerified     = true
                    };
                    db.Authors.Add(a);
                    _authorsSet.Add(author, a);
                }
                else
                {
                    a = _authorsSet[author];
                }
                Debug.WriteLine("Author lookup in " + DateTime.Now.Subtract(d1).TotalMilliseconds);

                DateTime  d2 = DateTime.Now;
                Publisher p  = null;
                if (!_publishersSet.ContainsKey(publisher))
                {
                    p = new Publisher()
                    {
                        Name       = publisher,
                        AddedBy    = profile,
                        IsVerified = true
                    };
                    db.Publishers.Add(p);
                    _publishersSet.Add(publisher, p);
                }
                else
                {
                    p = _publishersSet[publisher];
                }
                Debug.WriteLine("Author lookup in " + DateTime.Now.Subtract(d2).TotalMilliseconds);

                Book book = new Book()
                {
                    Authors     = new List <Author>(new Author[] { a }),
                    Title       = title,
                    AddedDate   = DateTime.Now,
                    Language    = _lang,
                    Shelf       = shelf,
                    ISBN        = isbn,
                    Publisher   = p,
                    Year        = year,
                    Description = _booksSplit[i, 6],
                    Pages       = _rnd.Next(1, 500),
                    Price       = _rnd.Next(10, 100)
                };

                //3 random genres bongo bong!
                var bookGenres = _allGenres.OrderBy(x => Guid.NewGuid().ToString()).Take(3).ToArray();
                book.Genres.Add(bookGenres[0]);

                db.Books.Add(book);

                //book pictures
                BookPicture bp = new BookPicture()
                {
                    Book   = book,
                    Key    = null,
                    Url    = imgurl,
                    IsMain = true,
                    Title  = "img title"
                };

                //book.Pictures = new List<BookPicture>();
                book.Pictures.Add(bp);

                Progress++;
                if (Cancel)
                {
                    break;
                }
            }
        }
 bool IRepo.UpdateBookPicture(BookPicture bookPicture)
 {
     throw new NotImplementedException();
 }
 bool IRepo.CreateBookPicture(int BookProviderId, BookPicture bookPicture)
 {
     throw new NotImplementedException();
 }
 public BookPicture AddBookPicture(BookPicture bookPicture)
 {
     _ctx.BookPictures.Add(bookPicture);
     _ctx.SaveChanges();
     return(bookPicture);
 }