Exemplo n.º 1
0
 /// <summary>
 /// 添加到opf
 /// </summary>
 /// <param name="chName"></param>
 /// <param name="img"></param>
 /// <param name="newBook"></param>
 public static void AddImgFileList(string chName, BookImage img,Book newBook)
 {
     var fileInfo = new BookFileInfo
     {
         chName = chName,
         fileAllName = "Images/" + img.storeName + img.ext,
         fileName = img.storeName + img.ext,
         clearName = img.storeName + img.ext,
         inContents = false,
         media_type = "image/" + img.ext.Replace(".", "").Replace("jpg", "jpeg")
     };
     newBook.filelist.Add(fileInfo);
 }
Exemplo n.º 2
0
        private void LoadCompleted( BookImage bookImage)
        {
            if (_index >= _length)
            {
                _book.completed.RemoveListener(LoadCompleted);
                SendComplete();
                _index = 0;
                _current = null;
                _length = 0;
                _book = null;
                enabled = false;
            }

            else
            {
                SendResolved(_index-1);
                LoadNext();
            }
        }
Exemplo n.º 3
0
        public ActionResult CreateImage(BookImage bookImage, IEnumerable <HttpPostedFileBase> files)
        {
            BookImage newBookImage = bookImage;

            foreach (var file in files)
            {
                if (files != null)
                {
                    Guid   code     = Guid.NewGuid();
                    string fileName = code + Path.GetExtension(file.FileName);
                    fileName = fileName.Replace(" ", "-");

                    string fileRoute = Path.Combine(Server.MapPath("~/Uploads/BookImage"), fileName);
                    file.SaveAs(fileRoute);
                    newBookImage.ImageUrl = fileName;
                }
                db.BookImages.Add(newBookImage);
                db.SaveChanges();
            }
            return(RedirectToAction("index"));
        }
Exemplo n.º 4
0
        void ReleaseDesignerOutlets()
        {
            if (BookImage != null)
            {
                BookImage.Dispose();
                BookImage = null;
            }

            if (BookISBNLabel != null)
            {
                BookISBNLabel.Dispose();
                BookISBNLabel = null;
            }

            if (BookPriceLabel != null)
            {
                BookPriceLabel.Dispose();
                BookPriceLabel = null;
            }

            if (BookSubtitleLabel != null)
            {
                BookSubtitleLabel.Dispose();
                BookSubtitleLabel = null;
            }

            if (BookTitleLabel != null)
            {
                BookTitleLabel.Dispose();
                BookTitleLabel = null;
            }

            if (BookUrlLabel != null)
            {
                BookUrlLabel.Dispose();
                BookUrlLabel = null;
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> UploadImage(ImageUploadViewModel uploadModel)
        {
            //string directory= @"C:\Users\Huseyin\source\repos\CetBookStore\CetBookStore\wwwroot\UserImages\";
            string directory = Path.Combine(hostEnvironment.WebRootPath, "UserImages");
            string fileName  = Guid.NewGuid().ToString() + "_" + uploadModel.ImageFile.FileName;

            string fullPath = Path.Combine(directory, fileName);

            using (var fileStream = new FileStream(fullPath, FileMode.Create))
            {
                await uploadModel.ImageFile.CopyToAsync(fileStream);
            }

            BookImage bookImage = new BookImage();

            bookImage.BookId   = uploadModel.BookId;
            bookImage.FileName = fileName;

            _context.BookImages.Add(bookImage);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(ManageImage), new { id = uploadModel.BookId }));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BookImage bookImage = db.BookImages.Find(id);
            var       mappings  = bookImage.BookImageMappings.Where(c => c.BookImageId == id);

            foreach (var mapping in mappings)
            {
                var updatedmappings = db.BookImageMappings.Where(c => c.BookImageId == mapping.BookId);
                foreach (var updatedmapping in updatedmappings)
                {
                    if (updatedmapping.ImageNumber > mapping.ImageNumber)
                    {
                        updatedmapping.ImageNumber--;
                    }
                }
            }

            System.IO.File.Delete(Request.MapPath(Constants.BookImagePath + bookImage.FileName));
            System.IO.File.Delete(Request.MapPath(Constants.BookThumbnailPath + bookImage.FileName));
            db.BookImages.Remove(bookImage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public void AddBookType(string title, string authors, decimal price, int quantity, Category category, string imageURL)
        {
            QuantityMap quantityMap = new QuantityMap()
            {
                Quantity = quantity
            };

            BookImage image = new BookImage()
            {
                URL = imageURL
            };

            BookType newBookType = new BookType()
            {
                Title       = title,
                Authors     = authors,
                Price       = price,
                QuantityMap = quantityMap,
                Category    = category,
                Image       = image
            };

            StorehouseManagementDao.SaveBookType(newBookType);
        }
Exemplo n.º 8
0
 public bool DeleteBookImage(BookImage bookImageToDelete)
 {
     _bookImageContext.Remove(bookImageToDelete);
     return(Save());
 }
Exemplo n.º 9
0
        public async Task <ActionResult <ApiResponse> > AddBookImage(int bookId, IFormFile image)
        {
            var responseModel = new ApiResponse();

            if (image == null)
            {
                responseModel.AddError(9);
                return(Ok(responseModel));
            }

            var book = await _dataAccess.Books
                       .Include(b => b.BookImage)
                       .Include(b => b.BookImages)
                       .FirstOrDefaultAsync(b => b.Disabled != true && b.Id == bookId);

            if (book == null)
            {
                responseModel.AddError(8);
                return(Ok(responseModel));
            }

            if (image.ContentType.Contains("image") == false)
            {
                responseModel.AddError(9);
                return(Ok(responseModel));
            }

            if (image.Length > _maxFileSize)
            {
                responseModel.AddError(10);
                return(Ok(responseModel));
            }

            var ext = Path.GetExtension(image.FileName);

            var name = Guid.NewGuid().ToString();

            var bookImage = new BookImage
            {
                ImageName = name + ext,
            };

            book.BookImages.Add(bookImage);

            if (book.BookImage == null)
            {
                book.BookImage = bookImage;
            }


            var currentDirectory = Directory.GetCurrentDirectory();

            var path = currentDirectory + "\\wwwroot" + _imagesFolderPath;

            Directory.CreateDirectory(path);

            using (var fileStream = new FileStream(path + name + ext, FileMode.Create))
            {
                await image.CopyToAsync(fileStream);
            }

            await _dataAccess.SaveChangesAsync();

            return(Ok(responseModel));
        }
Exemplo n.º 10
0
 public void EditImage(BookImage bookImage)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
        public ActionResult EditBook(EditBookModel model, bool deliveryBool1, bool deliveryBool2, bool deliveryBool3, bool deliveryBool4)
        {
            int counter = 0;

            if (!ModelState.IsValid)
            {
                List <string> errors = new List <string>();
                foreach (var modelStateVal in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateVal.Errors)
                    {
                        var errorMessage = error.ErrorMessage;
                        var exception    = error.Exception;
                        errors.Add(errorMessage);
                    }
                }
                foreach (string error in errors)
                {
                    ModelState.AddModelError("", error);
                }

                return(View());
            }
            var context = new AppDbContext();
            var book    = context.Books.Find(model.Id);

            if (model.Price == null)
            {
                model.Price = 0;
            }

            book.Author          = model.Author;
            book.Title           = model.Title;
            book.Genre           = model.Genre;
            book.Description     = model.Description;
            book.AddDate         = DateTime.Now;
            book.Price           = model.Price;
            book.Publisher       = model.Publisher;
            book.Changeable      = model.Changeable;
            book.PublicationDate = model.PublicationDate;
            book.SellerId        = System.Web.HttpContext.Current.User.Identity.GetUserId();
            book.Seller          = context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());



            bool bookIsAdded   = false;
            bool checkDelivery = false;

            if (deliveryBool1 == true)
            {
                counter++;
                if (!bookIsAdded)
                {
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;

                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Odbiór osobisty");
                if (oneDelivery != null)
                {
                    oneDelivery.Price           = model.DeliveryDict["Odbiór osobisty"];
                    oneDelivery.DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId;
                    oneDelivery.DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault();
                    context.SaveChanges();
                }
                else
                {
                    var del = new Delivery
                    {
                        Name            = "Odbiór osobisty",
                        Price           = model.DeliveryDict["Odbiór osobisty"],
                        DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                        DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                    };
                    context.DeliveryOptions.Add(del);
                    context.SaveChanges();
                }
            }
            else
            {
                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Odbiór osobisty");
                if (oneDelivery != null)
                {
                    context.DeliveryOptions.Remove(oneDelivery);
                }
            }
            if (deliveryBool2 == true)
            {
                counter++;
                if (!bookIsAdded)
                {
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;
                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka pocztowa - priorytetowa");
                if (oneDelivery != null)
                {
                    oneDelivery.Price           = model.DeliveryDict["Przesyłka pocztowa - priorytetowa"];
                    oneDelivery.DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId;
                    oneDelivery.DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault();
                    context.SaveChanges();
                }
                else
                {
                    var del = new Delivery
                    {
                        Name            = "Przesyłka pocztowa - priorytetowa",
                        Price           = model.DeliveryDict["Przesyłka pocztowa - priorytetowa"],
                        DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                        DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                    };
                    context.DeliveryOptions.Add(del);
                    context.SaveChanges();
                }
            }
            else
            {
                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka pocztowa - priorytetowa");
                if (oneDelivery != null)
                {
                    context.DeliveryOptions.Remove(oneDelivery);
                }
            }
            if (deliveryBool3 == true)
            {
                counter++;
                if (!bookIsAdded)
                {
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;

                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka pocztowa - ekonomiczna");
                if (oneDelivery != null)
                {
                    oneDelivery.Price           = model.DeliveryDict["Przesyłka pocztowa - ekonomiczna"];
                    oneDelivery.DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId;
                    oneDelivery.DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault();
                    context.SaveChanges();
                }
                else
                {
                    var del = new Delivery
                    {
                        Name            = "Przesyłka pocztowa - ekonomiczna",
                        Price           = model.DeliveryDict["Przesyłka pocztowa - ekonomiczna"],
                        DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                        DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                    };
                    context.DeliveryOptions.Add(del);
                    context.SaveChanges();
                }
            }
            else
            {
                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka pocztowa - ekonomiczna");
                if (oneDelivery != null)
                {
                    context.DeliveryOptions.Remove(oneDelivery);
                }
            }

            if (deliveryBool4 == true)
            {
                counter++;
                if (!bookIsAdded)
                {
                    context.Books.Attach(book);
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;

                var delivery = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                Debug.WriteLine(delivery.Count() + " " + counter);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka kurierska");
                if (oneDelivery != null)
                {
                    oneDelivery.Price           = model.DeliveryDict["Przesyłka kurierska"];
                    oneDelivery.DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId;
                    oneDelivery.DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault();
                    context.SaveChanges();
                }
                else
                {
                    var del = new Delivery
                    {
                        Name            = "Przesyłka kurierska",
                        Price           = model.DeliveryDict["Przesyłka kurierska"],
                        DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                        DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                    };
                    context.DeliveryOptions.Add(del);
                    context.SaveChanges();
                }
            }
            else
            {
                var delivery    = context.DeliveryOptions.Where(m => m.DeliveryPriceId == model.Id);
                var oneDelivery = delivery.SingleOrDefault(m => m.Name == "Przesyłka kurierska");
                if (oneDelivery != null)
                {
                    context.DeliveryOptions.Remove(oneDelivery);
                }
            }
            if (!checkDelivery)
            {
                ModelState.AddModelError("", "Proszę wybrać opcję dostawy");
                return(View());
            }

            byte[] uploadedFile = null;
            if (Request.Files != null && Request.Files.Count > 0)
            {
                int i = 0;
                foreach (string image in Request.Files)
                {
                    HttpPostedFileBase hpf2 = Request.Files.Get(i);
                    if (hpf2.InputStream.Length > 0)
                    {
                        Debug.WriteLine(image);
                        uploadedFile = new byte[hpf2.InputStream.Length];
                        hpf2.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
                        var img = context.BookImages.Where(m => m.BookImgId == model.Id);


                        BookImage[] imgTab = img.ToArray();
                        if (imgTab.Count() == 0)
                        {
                            var newImage = new BookImage
                            {
                                Image     = uploadedFile,
                                BookImg   = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault(),
                                BookImgId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId
                            };
                            context.BookImages.Add(newImage);
                            context.SaveChanges();
                        }
                        else
                        {
                            string nameImputImage = "BookImage" + i;
                            Debug.WriteLine("Przy edytowaniu książki: nameImputImage = ", nameImputImage, "image = ", image);
                            if (nameImputImage == image)
                            {
                                int imageId = imgTab[i].ImageId;
                                Debug.WriteLine("imageID = ", imageId);
                                img.Single(m => m.ImageId == imageId).Image     = uploadedFile;
                                img.Single(m => m.ImageId == imageId).BookImgId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId;
                                img.Single(m => m.ImageId == imageId).BookImg   = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault();
                                context.SaveChanges();
                            }
                        }
                    }
                }
                i++;
            }
            LuceneSearchIndexer.UpdateBooksIndex();
            return(RedirectToAction("index", "home"));
        }
Exemplo n.º 12
0
 public static List<BookImage> _searchImg(string folderPath,string addext = "")
 {
     List<BookImage> nlbi = new List<BookImage>();
     DirectoryInfo theFolder = new DirectoryInfo(folderPath);
     FileInfo[] fi = theFolder.GetFiles("*.*");
     foreach (FileInfo tmpfi in fi)
     {
         string extension = tmpfi.Extension.ToLower();
         if (extension == ".jpg" || extension == ".gif" || extension == ".png" || extension == ".bmp" || addext.IndexOf(extension) >= 0)
         //if (extension == ".jpg" || extension == ".jpeg")
         {
             string imgpath = tmpfi.FullName;
             string filename = imgpath.Substring(imgpath.LastIndexOf(@"\") + 1);
             string ext = filename.Substring(filename.LastIndexOf('.'));
             filename = filename.Substring(0, filename.LastIndexOf('.'));
             BookImage bi = new BookImage();
             {
                 bi.name = filename;
                 bi.storeName = filename;
                 bi.ext = ext;
                 bi.path = imgpath;
                 bi.type = ImageType.Default;
             }
             nlbi.Add(bi);
         }
     }
     return nlbi;
 }
Exemplo n.º 13
0
 public IResult Delete(BookImage bookImage)
 {
     FileHelper.Delete(bookImage.ImagePath);
     _bookImageDal.Delete(bookImage);
     return(new SuccessResult());
 }
Exemplo n.º 14
0
 public void AddImage(BookImage bookImage)
 {
     _bookImageRepository.AddImage(bookImage);
 }
Exemplo n.º 15
0
        internal async Task <bool> UpdateBookAsync(Book book, UpdateBookPostModel bookVM)
        {
            if (bookVM.AuthorId is not null)
            {
                book.AuthorId = bookVM.AuthorId ?? 0;
            }

            if (bookVM.BookName is not null)
            {
                book.BookName = bookVM.BookName;
            }
            if (bookVM.CategoryId is not null)
            {
                book.CategoryId = bookVM.CategoryId ?? 0;
            }
            if (bookVM.Description is not null)
            {
                book.Description = bookVM.Description;
            }
            if (bookVM.Price is not null)
            {
                book.Price = bookVM.Price ?? 0;
            }
            if (bookVM.Private is not null)
            {
                book.Private = bookVM.Private;
            }

            //Reup image
            var existingBookImage = await _bookstoreContext.BookImage
                                    .FirstOrDefaultAsync(images => images.BookId == book.Id);

            if (existingBookImage is null)
            {
                BookImage bookImage = new BookImage();
                bookImage.BookId = book.Id;

                if (bookVM.MainImage is not null)
                {
                    book.MainImage = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.MainImage.FileName;
                    _imageServices.UploadImage(bookVM.MainImage, book.MainImage);
                }

                if (bookVM.Image1 is not null)
                {
                    bookImage.Image1 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image1.FileName;
                    _imageServices.UploadImage(bookVM.Image1, bookImage.Image1);
                }
                if (bookVM.Image2 is not null)
                {
                    bookImage.Image2 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image2.FileName;
                    _imageServices.UploadImage(bookVM.Image2, bookImage.Image2);
                }
                if (bookVM.Image3 is not null)
                {
                    bookImage.Image3 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image3.FileName;
                    _imageServices.UploadImage(bookVM.Image3, bookImage.Image3);
                }
                if (bookVM.Image4 is not null)
                {
                    bookImage.Image4 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image4.FileName;
                    _imageServices.UploadImage(bookVM.Image4, bookImage.Image4);
                }

                await _bookstoreContext.BookImage
                .AddAsync(bookImage);
            }
            else
            {
                if (bookVM.MainImage is not null)
                {
                    book.MainImage = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.MainImage.FileName;
                    _imageServices.UploadImage(bookVM.MainImage, book.MainImage);
                }

                if (bookVM.Image1 is not null)
                {
                    existingBookImage.Image1 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image1.FileName;
                    _imageServices.UploadImage(bookVM.Image1, existingBookImage.Image1);
                }
                if (bookVM.Image2 is not null)
                {
                    existingBookImage.Image2 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image2.FileName;
                    _imageServices.UploadImage(bookVM.Image2, existingBookImage.Image2);
                }
                if (bookVM.Image3 is not null)
                {
                    existingBookImage.Image3 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image3.FileName;
                    _imageServices.UploadImage(bookVM.Image3, existingBookImage.Image3);
                }
                if (bookVM.Image4 is not null)
                {
                    existingBookImage.Image4 = DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + '_' + bookVM.Image4.FileName;
                    _imageServices.UploadImage(bookVM.Image4, existingBookImage.Image4);
                }
                _bookstoreContext.Entry(existingBookImage).State = EntityState.Modified;
            }

            _bookstoreContext.Entry(book).State = EntityState.Modified;

            try
            {
                return(await _bookstoreContext.SaveChangesAsync() != 0);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            };
        }
        public ActionResult Upload(HttpPostedFileBase[] files)
        {
            bool   allValid     = true;
            string inValidFiles = "";

            if (files[0] != null)
            {
                //if the user has entered less than ten files
                if (files.Length <= 10)
                {
                    //check they are all valid
                    foreach (var file in files)
                    {
                        if (!ValidateFile(file))
                        {
                            allValid      = false;
                            inValidFiles += ", " + file.FileName;
                        }
                    }
                    //if they are all valid then try to save them to disk
                    if (allValid)
                    {
                        foreach (var file in files)
                        {
                            try
                            {
                                SaveFileToDisk(file);
                            }
                            catch (Exception)
                            {
                                ModelState.AddModelError("FileName", "Sorry an error occurred saving the files to disk, please try again");
                            }
                        }
                    }
                    //else add an error listing out the invalid files
                    else
                    {
                        ModelState.AddModelError("FileName", "All files must be gif, png, jpeg or jpg and less than 2MB in size.The following files" + inValidFiles + " are not valid");
                    }
                }
                else
                {
                    ModelState.AddModelError("FileName", "Please only upload up to ten files at a time");
                }
            }
            else
            {
                //if the user has not entered a file return an error message
                ModelState.AddModelError("FileName", "Please choose a file");
            }
            if (ModelState.IsValid)
            {
                bool   duplicates     = false;
                bool   otherDbError   = false;
                string duplicateFiles = "";
                foreach (var file in files)
                {
                    //try and save each file
                    var bookToAdd = new BookImage {
                        FileName = file.FileName
                    };
                    try
                    {
                        db.BookImages.Add(bookToAdd);
                        db.SaveChanges();
                    }
                    //if there is an exception check if it is caused by a duplicate file
                    catch (DbUpdateException ex)
                    {
                        SqlException innerException = ex.InnerException.InnerException as
                                                      SqlException;
                        if (innerException != null && innerException.Number == 2601)
                        {
                            duplicateFiles           += ", " + file.FileName;
                            duplicates                = true;
                            db.Entry(bookToAdd).State = EntityState.Detached;
                        }
                        else
                        {
                            otherDbError = true;
                        }
                    }
                }
                if (duplicates)
                {
                    ModelState.AddModelError("FileName", "All files uploaded except the files" +
                                             duplicateFiles + ", which already exist in the system." +
                                             " Please delete them and try again if you wish to re-add them");
                    return(View());
                }
                else if (otherDbError)
                {
                    ModelState.AddModelError("FileName", "Sorry an error has occurred saving to the database, please try again");
                    return(View());
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemplo n.º 17
0
 private void LoadNext()
 {
     _current = _book.Get(_index++);
     _current.Load();
 }
Exemplo n.º 18
0
 /// <summary>
 /// Добавление информации о изображении
 /// </summary>
 /// <param name="bookImage"></param>
 public void AddImage(BookImage bookImage)
 {
     _dbSet.BookImages.Add(bookImage);
 }
Exemplo n.º 19
0
 public IResult Update(BookImage bookImage)
 {
     _bookImageDal.Update(bookImage);
     return(new SuccessResult(Messages.BookImageUpdated));
 }
Exemplo n.º 20
0
 public SetImg(BookImage _bookImage)
 {
     InitializeComponent();
     bookImage = _bookImage;
     this.DialogResult = DialogResult.Cancel;
 }
Exemplo n.º 21
0
        public ActionResult AddBook(SellBookModel model, bool deliveryBool1, bool deliveryBool2, bool deliveryBool3, bool deliveryBool4, IEnumerable <HttpPostedFileBase> files)
        {
            List <bool> CheckList = new List <bool> {
                deliveryBool1, deliveryBool2, deliveryBool3, deliveryBool4
            };


            if (!ModelState.IsValid)
            {
                List <string> errors = new List <string>();
                foreach (var modelStateVal in ViewData.ModelState.Values)
                {
                    foreach (var error in modelStateVal.Errors)
                    {
                        var errorMessage = error.ErrorMessage;
                        var exception    = error.Exception;
                        errors.Add(errorMessage);
                    }
                }
                foreach (string error in errors)
                {
                    ModelState.AddModelError("", error);
                }

                return(View());
            }
            var context = new AppDbContext();

            Debug.WriteLine(context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId()).BankNumber + model.Price + deliveryBool1);
            if (context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId()).BankNumber == "Nie podano" && model.Price != 0 && deliveryBool1 == false)
            {
                ModelState.AddModelError("", "W ustawieniach użytkownika nie podano numeru konta potrzebnego do ewentualnej finalizacji tranzakcji. Aby wystawić książkę na sprzedaż należy uzupełnić te dane.");
                return(View());
            }

            {
            }


            if (model.Price == null)
            {
                model.Price = 0;
            }

            var book = new Book
            {
                Author          = model.Author,
                Title           = model.Title,
                Genre           = model.Genre,
                Description     = model.Description,
                AddDate         = DateTime.Now,
                isChanged       = false,
                isSold          = false,
                Price           = model.Price,
                Publisher       = model.Publisher,
                Changeable      = model.Changeable,
                PublicationDate = model.PublicationDate,
                SellerId        = System.Web.HttpContext.Current.User.Identity.GetUserId(),
                Seller          = context.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId()),
            };
            bool bookIsAdded   = false;
            bool checkDelivery = false;

            if (deliveryBool1 == true)
            {
                if (!bookIsAdded)
                {
                    context.Books.Add(book);
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                bookIsAdded   = true;
                checkDelivery = true;
                var delivery = new Delivery
                {
                    Name            = "Odbiór osobisty",
                    Price           = model.DeliveryPrice[0],
                    DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                    DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                };
                context.DeliveryOptions.Add(delivery);
                context.SaveChanges();
            }
            if (deliveryBool2 == true)
            {
                if (!bookIsAdded)
                {
                    context.Books.Add(book);
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;
                var delivery = new Delivery
                {
                    Name            = "Przesyłka pocztowa - priorytetowa",
                    Price           = model.DeliveryPrice[1],
                    DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                    DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                };
                context.DeliveryOptions.Add(delivery);
                context.SaveChanges();
            }


            if (deliveryBool3 == true)
            {
                if (!bookIsAdded)
                {
                    context.Books.Add(book);
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;
                var delivery = new Delivery
                {
                    Name            = "Przesyłka pocztowa - ekonomiczna",
                    Price           = model.DeliveryPrice[2],
                    DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                    DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                };
                context.DeliveryOptions.Add(delivery);
                context.SaveChanges();
            }
            if (deliveryBool4 == true)
            {
                if (!bookIsAdded)
                {
                    context.Books.Add(book);
                    context.SaveChanges();
                    bookIsAdded = true;
                }
                checkDelivery = true;
                var delivery = new Delivery
                {
                    Name            = "Przesyłka kurierska",
                    Price           = model.DeliveryPrice[3],
                    DeliveryPriceId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId,
                    DeliveryPrices  = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                };

                context.DeliveryOptions.Add(delivery);
                context.SaveChanges();
            }


            if (!checkDelivery)
            {
                ModelState.AddModelError("", "Proszę wybrać opcję dostawy");
                return(View());
            }

            byte[]    uploadedFile = null;
            BookImage bookImage    = null;

            if (Request.Files != null)
            {
                int i = 0;
                foreach (string image in Request.Files)
                {
                    HttpPostedFileBase hpf = Request.Files[image] as HttpPostedFileBase;
                    if (image != "files")
                    {
                        if (hpf.InputStream.Length > 0)
                        {
                            uploadedFile = new byte[hpf.InputStream.Length];
                            Debug.WriteLine(uploadedFile.Length);
                            hpf.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
                            bookImage = new BookImage {
                                Image = uploadedFile, BookImgId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId, BookImg = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                            };
                            context.BookImages.Add(bookImage);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        HttpPostedFileBase hpf2 = Request.Files.Get(i);
                        if (hpf2.InputStream.Length > 0)
                        {
                            uploadedFile = new byte[hpf2.InputStream.Length];
                            Debug.WriteLine(uploadedFile.Length);
                            hpf2.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
                            bookImage = new BookImage {
                                Image = uploadedFile, BookImgId = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault().BookId, BookImg = context.Books.OrderByDescending(o => o.BookId).FirstOrDefault()
                            };
                            context.BookImages.Add(bookImage);
                            context.SaveChanges();
                        }
                    }
                    i++;
                }



                //próba skalowania obrazu
                //Image image = Image.FromStream(new MemoryStream(uploadedFile));
                //Image newImage;
                //newImage = ScaleImage(image, 300, 150);
                //var ms = new MemoryStream();
                //newImage.Save(ms, ImageFormat.Gif);
                //ms.ToArray();
                //uploadedFile = ms.ToArray();
                //model.BookImage.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
            }
            LuceneSearchIndexer.UpdateBooksIndex();
            return(RedirectToAction("index", "home"));
        }
Exemplo n.º 22
0
        public virtual ActionResult AddPost(AddPostModel postModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(MVC.Admin.Shared.Views._ValidationSummery));
            }

            postModel.PostBody         = postModel.PostBody.ToSafeHtml();
            postModel.Book.Description = postModel.Book.Description.ToSafeHtml();

            var post = new Post
            {
                Body          = postModel.PostBody,
                CommentStatus = postModel.PostCommentStatus,
                CreatedDate   = DateAndTime.GetDateTime(),
                Description   = postModel.PostDescription,
                Keyword       = postModel.PostKeyword,
                Status        = postModel.PostStatus.ToString().ToLower(),
                Title         = postModel.PostTitle
            };

            var book = new Book
            {
                Author      = postModel.Book.Author,
                Description = postModel.Book.Description,
                ISBN        = postModel.Book.ISBN,
                Language    = postModel.Book.Language,
                Name        = postModel.Book.Name,
                Year        = postModel.Book.Year,
                Publisher   = postModel.Book.Publisher,
                Page        = postModel.Book.Page
            };

            var bookImage = new BookImage
            {
                Path         = postModel.BookImage.Path,
                Title        = postModel.BookImage.Title,
                Description  = postModel.BookImage.Description,
                UploadedDate = DateAndTime.GetDateTime()
            };

            var links = new List <DownloadLink>();

            if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink1.Link))
            {
                links.Add(postModel.DownloadLinks.DownloadLink1);
            }
            if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink2.Link))
            {
                links.Add(postModel.DownloadLinks.DownloadLink2);
            }
            if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink3.Link))
            {
                links.Add(postModel.DownloadLinks.DownloadLink3);
            }
            if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink4.Link))
            {
                links.Add(postModel.DownloadLinks.DownloadLink4);
            }

            post.Book          = book;
            post.DownloadLinks = links;
            post.Book.Image    = bookImage;
            post.User          = _userService.GetUserByUserName(User.Identity.Name);
            post.Labels        = _labelService.GetLabelsById(postModel.LabelId);

            _postService.AddPost(post);
            _uow.SaveChanges();

            #region Indexing new book by Lucene.NET

            //Index the new book lucene.NET
            Post lastPost = _postService.Find(post.Id);
            LuceneBookSearch.AddUpdateLuceneIndex(new LuceneBookModel
            {
                Author      = lastPost.Book.Author,
                Description = HtmlUtility.RemoveHtmlTags(lastPost.Book.Description),
                ISBN        = lastPost.Book.ISBN,
                Name        = lastPost.Book.Name,
                PostId      = lastPost.Id,
                Publisher   = lastPost.Book.Publisher,
                Title       = lastPost.Title
            });

            #endregion

            return(PartialView(MVC.Admin.Shared.Views._Alert,
                               new Alert {
                Message = "پست جدید با موقیت در سیستم ثبت شد", Mode = AlertMode.Success
            }));
        }
Exemplo n.º 23
0
 public void AddImage(BookImage bookImage)
 {
     _images.Add(bookImage);
 }
Exemplo n.º 24
0
 private static string _getStoreName(BookImage bookImage)
 {
     if (bookImage.type == ImageType.Cover)
         return "cover";
     else if (bookImage.type == ImageType.Contents)
         return "contents";
     if (bookImage.type == ImageType.BackCover)
         return "backcover";
     else
     {
         int i = bookImage.index;
         string nameIndex = i <= 9 ? "00" : (i <= 99 ? "0" : "");
         if (bookImage.type == ImageType.InBook)
         {
             return "inBook" + nameIndex + i.ToString();
         }
         if (bookImage.type == ImageType.Default)
         {
             return "other" + nameIndex + i.ToString();
         }
         else if (bookImage.type == ImageType.Illustration)
         {
             return "Illus" + nameIndex + i.ToString();
         }
         else
         {
             return DateTime.Now.Millisecond.ToString();
         }
     }
 }
Exemplo n.º 25
0
 public IResult Delete(BookImage bookImage)
 {
     _bookImageDal.Delete(bookImage);
     return(new SuccessResult(Messages.BookImageDeleted));
 }