Ejemplo n.º 1
0
        public ActionResult Create(BookLetSalesViewModel model)
        {
            List <BookLetViewModel> bookList = bookLetSaleServices.GetAllBookLetAvaliable();
            var fullbookList = new SelectList(bookList, "Id", "Id");

            ViewBag.bookList = fullbookList;
            if (bookList.Count() == 0)
            {
                List <SelectListItem> emptyList = new List <SelectListItem>();
                emptyList.Add(new SelectListItem {
                    Text = "-- No Book Is Avaliable --", Value = ""
                });
                ViewBag.bookList = emptyList;
            }
            if (ModelState.IsValid)
            {
                try
                {
                    bookLetSaleServices.SaleBook(model);
                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View(model));
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
 public ActionResult Edit(int id, BookLetSalesViewModel model)
 {
     try
     {
         bookLetSaleServices.UpdateBookLetSale(model);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(model));
     }
 }
Ejemplo n.º 3
0
        public BookLetSalesViewModel GetBookLetSaleById(int?Id)
        {
            BookLetSalesViewModel book = db.BookLetSales.Where(x => x.Serial == Id.Value).Select(x => new BookLetSalesViewModel
            {
                Serial       = x.Serial,
                Date         = x.Date,
                BookLetId    = x.BookLetId,
                CustomerId   = x.CustomerId,
                CustomerName = x.CustomerName
            }).FirstOrDefault();

            return(book);
        }
Ejemplo n.º 4
0
        public void SaleBook(BookLetSalesViewModel model)
        {
            BookLetSales book = new BookLetSales {
                Date = model.Date, BookLetId = model.BookLetId, CustomerId = model.CustomerId, CustomerName = model.CustomerName
            };

            db.BookLetSales.Add(book);
            db.SaveChanges();
            BookLetTable oldBook = db.BookLet.Find(model.BookLetId);

            db.Entry(oldBook).State = EntityState.Modified;
            oldBook.Status          = 1;
            db.SaveChanges();
        }
Ejemplo n.º 5
0
        public ActionResult Create()
        {
            List <BookLetViewModel> bookList = bookLetSaleServices.GetAllBookLetAvaliable();
            var fullbookList = new SelectList(bookList, "Id", "Id");

            ViewBag.bookList = fullbookList;
            if (bookList.Count() == 0)
            {
                List <SelectListItem> emptyList = new List <SelectListItem>();
                emptyList.Add(new SelectListItem {
                    Text = "-- No Book Is Avaliable --", Value = ""
                });
                ViewBag.bookList = emptyList;
            }
            BookLetSalesViewModel book = new BookLetSalesViewModel();

            return(View(book));
        }
Ejemplo n.º 6
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            BookLetSalesViewModel bookLetSale = new BookLetSalesViewModel();

            bookLetSale = bookLetSaleServices.GetBookLetSaleById(id);
            if (bookLetSale == null)
            {
                return(NotFound());
            }
            List <BookLetViewModel> allBookAvailableIncludeCurrent = bookLetSaleServices.GetAllBookLetAvaliable();
            BookLetViewModel        book = bookLetServices.GetBookLetById(bookLetSale.BookLetId);

            allBookAvailableIncludeCurrent.Add(book);
            ViewBag.bookList = new SelectList(allBookAvailableIncludeCurrent.OrderBy(x => x.Id), "Id", "Id", book);
            return(View(bookLetSale));
        }
Ejemplo n.º 7
0
        public void UpdateBookLetSale(BookLetSalesViewModel model)
        {
            BookLetSales bookSale = db.BookLetSales.Find(model.Serial);
            BookLetTable oldbook  = db.BookLet.Find(bookSale.BookLetId);

            db.Entry(oldbook).State = EntityState.Modified;
            oldbook.Status          = 0;

            db.Entry(bookSale).State = EntityState.Modified;
            bookSale.Date            = model.Date;
            bookSale.BookLetId       = model.BookLetId;
            bookSale.CustomerId      = model.CustomerId;
            bookSale.CustomerName    = model.CustomerName;

            BookLetTable newbook = db.BookLet.Find(model.BookLetId);

            db.Entry(newbook).State = EntityState.Modified;
            newbook.Status          = 1;

            db.SaveChanges();
        }