public ActionResult DonateBook(DonateVM model)
        {
            HttpPostedFileBase file    = Request.Files["ImageData"];
            HomeRepository     service = new HomeRepository();
            int i = service.UploadImageInDataBase(file, model);

            if (i == 1)
            {
                return(RedirectToAction("DonateSuccess"));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public int UploadImageInDataBase(HttpPostedFileBase file, DonateVM donateModel)
        {
            int   i;
            Books existingBook = null;

            existingBook = db.Book.Where(b => b.Title == donateModel.Title).FirstOrDefault();



            if (existingBook != null)
            {
                existingBook.QuantityAvailable += donateModel.NumBookDonated;
                db.Entry(existingBook).State    = EntityState.Modified;
                i = db.SaveChanges();
            }
            else
            {
                donateModel.Image = ConvertToBytes(file);
                //Books GenreId = db.Book.Where(s => s.GenreId == donateModel.GenreId).FirstOrDefault();

                var Content = new Books
                {
                    Id = donateModel.Id,
                    //UserId =donateModel.UserId,
                    //Subject sub = ctx.Subjects.FirstOrDefault(s => s.SubjectId == 202);

                    Genres  = db.Genre.Find(donateModel.GenreId),
                    Authors = db.Author.Find(donateModel.AuthorId),
                    //GenreId = db.Genre.Find(donateModel.GenreName).Id,

                    Title             = donateModel.Title,
                    ISBN              = donateModel.ISBN,
                    QuantityAvailable = donateModel.NumBookDonated,
                    QuantityReserved  = "No",
                    Image             = donateModel.Image
                };

                db.Book.Add(Content);
                i = db.SaveChanges();
            }

            return(i);
        }
        // GET: Books/Cart/5
        public ActionResult Cart(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //FIND book by bookID
            Books bookRec = db.Book.Find(id);

            if (bookRec == null)
            {
                return(HttpNotFound());  //replace with user friendly message, NOT 404 NOT FOUND
            }

            DonateVM vm = new DonateVM();

            vm.GenreId  = bookRec.GenreId;
            vm.AuthorId = bookRec.AuthorId;
            vm.Title    = bookRec.Title;
            vm.ISBN     = bookRec.ISBN;
            vm.Id       = bookRec.Id;

            //Decrment the QTY Available
            bookRec.QuantityAvailable -= 1;
            vm.QuantityAvailable       = bookRec.QuantityAvailable;
            //vm.QuantityAvailable -= vm.QuantityAvailable;

            //INcrement the QTY Reserved
            // bookRec.QuantityReserved.ToString +=;

            vm.QuantityReserved = bookRec.QuantityReserved;
            //Update the record
            db.Entry(bookRec).State = EntityState.Modified;
            db.SaveChanges();

            //ViewBag.PickUpDueDate = BusinessDays.GetDueDate(receivedDatedTime, workdays, PickUpDueDate);
            return(View(vm));
        }
        public ActionResult Create(/*[Bind(Include = "Title,GenreId,AuthorId,ISBN,Image,NumBookDonated")]*/ DonateVM model)
        {
            //return View(donatevm);
            HttpPostedFileBase file    = Request.Files["ImageData"];
            HomeRepository     service = new HomeRepository();
            int i = service.UploadImageInDataBase(file, model);

            if (i == 1)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }