public async Task <IActionResult> Edit(Guid id, [Bind("BookCarId,CarId,Location,PickDate,ReturnDate,CarName")] BookCar bookCar)
        {
            if (id != bookCar.BookCarId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _bookCarService.UpdateBookCar(id, bookCar);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_bookCarService.BookCarExists(bookCar.BookCarId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bookCar));
        }
예제 #2
0
        public IActionResult Crud([FromBody] ScheduleViewModel <BookCarViewModel> payload)
        {
            if (payload.added.Count > 0)
            {
                BookCarViewModel value   = payload.added[0];
                BookCar          BookCar = new BookCar();
                value.BookCarId = 0;
                _mapper.Map <BookCarViewModel, BookCar>(value, BookCar);
                _functionalService.Insert <BookCar>(BookCar);
            }
            if (payload.changed.Count > 0)
            {
                BookCarViewModel value = payload.changed[0];
                _functionalService.Update <BookCarViewModel, BookCar>(value, Convert.ToInt32(value.BookCarId));
            }
            if (payload.deleted.Count > 0)
            {
                BookCarViewModel value = payload.deleted[0];
                var result             = _functionalService.Delete <BookCar>(Convert.ToInt32(value.BookCarId));
            }

            List <BookCar> books = _functionalService.GetList <BookCar>().ToList();

            return(Ok(books));
        }
 public ActionResult DatXe(FormCollection formCollection)
 {
     try
     {
         BookCar         bookCar   = new BookCar();
         List <CartItem> cartItems = Laygiohang();
         bookCar.FullNameUser    = formCollection["hoTen"];
         bookCar.NumberPhoneUser = formCollection["sdt"];
         bookCar.CardIDUser      = formCollection["cmnd"];
         bookCar.AddressUser     = formCollection["diaChi"];
         bookCar.DateBookCar     = DateTime.Now;
         var dateOfReceive = String.Format("{0:dd/MM/yyyy}", formCollection["ngayNhan"]);
         bookCar.DateOfReceive = DateTime.Parse(dateOfReceive);
         var dateReturn = String.Format("{0:dd/MM/yyyy}", formCollection["ngayTra"]);
         bookCar.DateReturn    = DateTime.Parse(dateReturn);
         bookCar.PaymentStatus = false;
         db.BookCars.Add(bookCar);
         foreach (var item in cartItems)
         {
             bookCar.CarProductsId = item.id;
             bookCar.TotalRental   = (decimal)item.giaThue;
             db.BookCars.Add(bookCar);
         }
         db.SaveChanges();
         Session["Giohang"] = null;
     }
     catch (System.FormatException)
     {
     }
     return(RedirectToAction("Xacnhan", "CartItemBC"));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            BookCar bookCar = db.BookCars.Find(id);

            db.BookCars.Remove(bookCar);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "BookCarsId,DateBookCar,UserCustomersId")] BookCar bookCar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookCar).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserCustomersId = new SelectList(db.UserCustomers, "UserCustomersId", "FullNameUser", bookCar.UserCustomersId);
     return(View(bookCar));
 }
 public ActionResult Edit([Bind(Include = "BookCarsId,DateBookCar,TotalRental,DateOfReceive,DateReturn,PaymentStatus,FullNameUser,CardIDUser,AddressUser,NumberPhoneUser,EmailUser,CarProductsId")] BookCar bookCar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bookCar).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CarProductsId = new SelectList(db.CarProducts, "CarProductsId", "ModelCar", bookCar.CarProductsId);
     return(View(bookCar));
 }
        public ActionResult Create([Bind(Include = "BookCarsId,DateBookCar,UserCustomersId")] BookCar bookCar)
        {
            if (ModelState.IsValid)
            {
                db.BookCars.Add(bookCar);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserCustomersId = new SelectList(db.UserCustomers, "UserCustomersId", "FullNameUser", bookCar.UserCustomersId);
            return(View(bookCar));
        }
예제 #8
0
        public IActionResult Add([FromBody] ScheduleViewModel <BookCar> payload)
        {
            if (payload.value != null)
            {
                BookCar value = payload.value;
                value.BookCarId = 0;
                _functionalService.Insert <BookCar>(value);
            }
            List <BookCar> books = _functionalService.GetList <BookCar>().ToList();

            return(Ok(books));
        }
        public async Task <IActionResult> Create(BookCarDto bookCar)
        {
            try
            {
                var newBookCar = new BookCar(bookCar);
                await _bookCarService.CreateBookCar(newBookCar);

                return(Ok(bookCar));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        // GET: BookCars/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookCar bookCar = db.BookCars.Find(id);

            if (bookCar == null)
            {
                return(HttpNotFound());
            }
            return(View(bookCar));
        }
예제 #11
0
        public async Task <bool> CreateBookCar(BookCar bookCar)
        {
            try
            {
                _bookCarRepository.Create(bookCar);
                await _bookCarRepository.SaveAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
        // GET: BookCars/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookCar bookCar = db.BookCars.Find(id);

            if (bookCar == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserCustomersId = new SelectList(db.UserCustomers, "UserCustomersId", "FullNameUser", bookCar.UserCustomersId);
            return(View(bookCar));
        }
        // GET: AdministratorCP/BookCars/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BookCar bookCar = db.BookCars.Find(id);

            if (bookCar == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CarProductsId = new SelectList(db.CarProducts, "CarProductsId", "ModelCar", bookCar.CarProductsId);
            return(View(bookCar));
        }
예제 #14
0
        public async Task <bool> UpdateBookCar(Guid id, BookCar bookCar)
        {
            try
            {
                await GetBookCarById(id);

                _bookCarRepository.Update(bookCar);
                await _bookCarRepository.SaveAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }