Example #1
0
        public ActionResult Update(Book book, HttpPostedFileBase picture, int categoryId)
        {
            try
            {
                BookDao         bookDao         = new BookDao();
                BookCategoryDao bookCategoryDao = new BookCategoryDao();

                BookCategory bookCategory = bookCategoryDao.GetbyId(categoryId);

                KnihovnaKategorieDao knihovnaKategorieDao = new KnihovnaKategorieDao();
                KnihovnaUserDao      knihovnaUserDao      = new KnihovnaUserDao();

                KnihovnaKategorie knihovnaKategorie = book.Kategorie;
                // KnihovnaUser knihovnaUser = knihovnaUserDao.GetbyId(book.OwnerId.Id);

                book.Category  = bookCategory;
                book.Kategorie = knihovnaKategorie;
                //   book.OwnerId = knihovnaUser;

                if (picture != null)
                {
                    Image image     = Image.FromStream(picture.InputStream);
                    Image smalImage = ImageHelper.ResizeImageHighQuality(image, 200, 200);

                    Bitmap btmBitmap = new Bitmap(smalImage);
                    Guid   guid      = Guid.NewGuid();

                    string imageName = guid.ToString() + ".jpg";
                    btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName,
                                   ImageFormat.Jpeg); // Je potřeba namapovat cestu!

                    btmBitmap.Dispose();
                    image.Dispose();



                    System.IO.File.Delete(Server.MapPath("~/Uploads/Book/") + book.ImageName);

                    book.ImageName = imageName;
                }

                bookDao.Update(book);

                TempData["scs"] = "Kniha " + book.Name + " byla upravena";
            }
            catch (Exception e)
            {
                throw;
            }

            return(RedirectToAction("Index", "Books"));
        }
Example #2
0
        public ActionResult Update(Book book, HttpPostedFileBase picture, int categoryId, string sumText, string userName)
        {
            try
            {
                BookDao         bookDao         = new BookDao();
                BookCategoryDao bookCategoryDao = new BookCategoryDao();

                BookCategory bookCategory = bookCategoryDao.GetbyId(categoryId);

                book.Category         = bookCategory;
                book.Version          = book.Version + 0.1;
                book.LastEditDateTime = DateTime.Now;

                KnihovnaUser usr = new KnihovnaUserDao().GetByLogin(userName);

                // Zaneseme verzování
                BookVersion ver = new BookVersion();
                ver.Id           = Books.Counter();
                ver.SumText      = sumText;
                ver.Version      = book.Version;
                ver.ChangedBy    = usr.Id;
                ver.Date         = DateTime.Now;
                ver.IsApproved   = false;
                ver.IsSuggestion = false;
                ver.Text         = book.Description;
                ver.PostId       = book.Id;

                BookVersionDao vd = new BookVersionDao();
                vd.Create(ver);


                if (picture != null)
                {
                    Image image     = Image.FromStream(picture.InputStream);
                    Image smalImage = ImageHelper.ScaleImage(image, 200, 200);

                    Bitmap btmBitmap = new Bitmap(smalImage);
                    Guid   guid      = Guid.NewGuid();

                    string imageName = guid.ToString() + ".jpg";
                    btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName, ImageFormat.Jpeg); // Je potřeba namapovat cestu!

                    btmBitmap.Dispose();
                    image.Dispose();

                    System.IO.File.Delete(Server.MapPath("~/Uploads/Book/") + book.ImageName);

                    book.ImageName = imageName;
                }

                bookDao.Update(book);

                TempData["scs"] = "Kniha " + book.Name + " byla upravena";
            }
            catch (Exception e)
            {
                throw;
            }

            return(RedirectToAction("Index", "Books"));
        }
Example #3
0
        public ActionResult Add(Book book, HttpPostedFileBase picture, int categoryId)
        {
            //if (ModelState.IsValid)
            {
                KnihovnaUserDao      d = new KnihovnaUserDao();
                KnihovnaUser         u = d.GetByLogin(User.Identity.Name);
                KnihovnaKategorieDao k = new KnihovnaKategorieDao();

                Book b = new Book()
                {
                    Name             = book.Name,
                    Author           = book.Author,
                    PublishedYear    = book.PublishedYear,
                    Id               = Books.Counter(),
                    Description      = book.Description,
                    OwnerId          = u,
                    Kategorie        = k.GetbyId(2),
                    LastEditDateTime = DateTime.Now,
                    Version          = 1,
                    IsPayed          = false,
                    UnlockPrice      = 0,
                    MinimalLevel     = 0
                };


                if (picture != null)
                {
                    var z = picture.ContentLength;

                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image     = Image.FromStream(picture.InputStream);
                        Image smalImage = ImageHelper.ScaleImage(image, 200, 200);


                        Bitmap btmBitmap = new Bitmap(smalImage);
                        Guid   guid      = Guid.NewGuid();

                        string imageName = guid.ToString() + ".jpg";
                        btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName, ImageFormat.Jpeg); // Je potřeba namapovat cestu!

                        btmBitmap.Dispose();
                        image.Dispose();

                        b.ImageName = imageName;
                    }
                }

                BookCategoryDao bookCategoryDao = new BookCategoryDao();
                BookCategory    bookCategory    = bookCategoryDao.GetbyId(5);

                b.Category  = bookCategory;
                b.Author    = "nějaká děvka";
                b.SectionId = categoryId;

                BookDao bookDao    = new BookDao();
                int     identifier = (int)bookDao.Create(b);

                BookVersionDao bv = new BookVersionDao();
                BookVersion    v  = new BookVersion();

                v.Text         = b.Description;
                v.ChangedBy    = u.Id;
                v.Date         = DateTime.Now;
                v.Id           = Books.Counter();
                v.IsApproved   = true;
                v.IsSuggestion = false;
                v.PostId       = identifier;
                v.SumText      = "Původní verze";
                v.Version      = 1;

                bv.Create(v);


                LevelUp.NewPost(u, d);
                NovinkyGenerator.PridatNovinku(b, u.Id);

                // Notifikace
                TempData["scs"] = "V pořádku";
            }
            // else
            {
                return(View("Create", book)); // Vrátím vstupní data
            }

            return(RedirectToAction("Index"));
        }
Example #4
0
        public ActionResult Add(Book book, HttpPostedFileBase picture, int categoryId)
        {
            if (ModelState.IsValid)
            {
                Book b = new Book()
                {
                    Name             = book.Name,
                    Author           = book.Author,
                    PublishedYear    = book.PublishedYear,
                    Id               = Books.Counter(),
                    Description      = book.Description,
                    OwnerId          = new KnihovnaUserDao().GetByLogin(User.Identity.Name),
                    Kategorie        = new KnihovnaKategorieDao().GetbyId(2),
                    LastEditDateTime = DateTime.Now,
                    Version          = 1,
                    IsPayed          = false,
                    UnlockPrice      = 0,
                    MinimalLevel     = 0
                };


                if (picture != null)
                {
                    var z = picture.ContentLength;

                    if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")
                    {
                        Image image     = Image.FromStream(picture.InputStream);
                        Image smalImage = ImageHelper.ResizeImageHighQuality(image, 200, 200);


                        Bitmap btmBitmap = new Bitmap(smalImage);
                        Guid   guid      = Guid.NewGuid();

                        string imageName = guid.ToString() + ".jpg";
                        btmBitmap.Save(Server.MapPath("~/Uploads/Book/") + imageName,
                                       ImageFormat.Jpeg); // Je potřeba namapovat cestu!

                        btmBitmap.Dispose();
                        image.Dispose();

                        b.ImageName = imageName;
                    }
                }

                BookCategoryDao bookCategoryDao = new BookCategoryDao();
                BookCategory    bookCategory    = bookCategoryDao.GetbyId(categoryId);

                b.Category = bookCategory;

                BookDao bookDao = new BookDao();
                bookDao.Create(b);

                NovinkyGenerator.PridatNovinku(b, new KnihovnaUserDao().GetByLogin(User.Identity.Name).Id);

                // Notifikace
                TempData["scs"] = "V pořádku";
            }
            else
            {
                return(View("Create", book)); // Vrátím vstupní data
            }

            return(RedirectToAction("Index"));
        }