Beispiel #1
0
        public ActionResult Addbook(Book book, HttpPostedFileBase picture, int categoryId)
        {
            if ( ModelState.IsValid )
            {

                if ( picture != null )
                {
                    if ( picture.ContentType == "image/jpeg" || picture.ContentType == "image/png" )
                    {
                        Image image = Image.FromStream(picture.InputStream);

                        if ( image.Height > 200 || image.Width > 200 )
                        {
                            Image small = Helper.ImageHelper.ScaleImage(image, 200, 200);
                            Bitmap b = new Bitmap(small);

                            Guid guid = Guid.NewGuid();
                            string imageName = guid.ToString() + ".jpg";

                            b.Save(Server.MapPath("~/uploads/aticleImage/" + imageName), ImageFormat.Jpeg);
                            b.Save(Server.MapPath("~/uploads/articleImage/" + imageName), ImageFormat.Jpeg);

                            small.Dispose();
                            b.Dispose();

                            book.ImageName = imageName;
                        }
                        else
                        {
                            picture.SaveAs(Server.MapPath("~/uploads/Article/" + picture.FileName));
                        }
                    }
                }
                BookCategoryDao bookCategoryDao = new BookCategoryDao();

                BookCategory bookCategory = bookCategoryDao.GetById(categoryId);
                book.Category = bookCategory;
                book.PosteDate = DateTime.Now;
                BookDao bookDao = new BookDao();

                bookDao.Create(book);

                TempData["message-success"] = "Článek byl přidán";

            }
            else
            {
                return View("Create", book);
            }

            return RedirectToAction("Index");
        }
        public void create()
        {
            BookDao xyz = new BookDao();

            xyz.Create(this);
        }
Beispiel #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"));
        }
Beispiel #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"));
        }