Esempio n. 1
0
        public ActionResult CreateBooking(Booking booking)
        {
            if (ModelState.IsValid)
            {
                var db          = new LocationVoiture.Data.LocationContext();
                var CurrentUser = db.Users.Where(x => x.UserName.Equals(User.Identity.Name)).FirstOrDefault();

                var carId = (int)Session["CarId"];
                booking.UserId = CurrentUser.UserID;
                booking.CarId  = carId;



                booking.bookingState       = BookingState.Sent;
                booking.BookingRequestDate = DateTime.Now;
                serviceBooking.Add(booking);
                serviceBooking.Commit();
                Car car = myService.GetById(carId);

                // booking.Car.User.Token;
                NotificationHelper.SendFCMNotificationWithBadgeAndroid(car.User.Token, "Booking Request", "New Rental Request", 1, 0, "application/json");
                return(RedirectToAction("Index"));
            }
            return(View(booking));
        }
Esempio n. 2
0
        public ActionResult Create(Car car, HttpPostedFileBase[] files)
        {
            if (ModelState.IsValid)
            {
                var db          = new LocationVoiture.Data.LocationContext();
                var CurrentUser = db.Users.Where(x => x.UserName.Equals(User.Identity.Name)).FirstOrDefault();
                if (CurrentUser.IsActive == true)
                {
                    car.UserId    = CurrentUser.UserID;
                    car.Available = true;
                    car.Active    = true;
                    myService.Add(car);
                    myService.Commit();
                    serviceImage.AddPictureToCar(car.CarID, files);

                    ViewBag.Result = "Car was added successfully!";
                }
                else
                {
                    ViewBag.Result = "You have to activate you account if you want to add a car";
                }
            }
            var res  = serviceCarModel.GetMany().ToList();
            var sub  = serviceSubCategory.GetMany().ToList();
            var year = serviceCreation.GetMany().ToList();
            var type = serviceType.GetMany().ToList();

            ViewBag.TypeId         = new SelectList(type, "TypeId", "Name");
            ViewBag.CreationYearId = new SelectList(year, "CreationYearId", "Name");
            ViewBag.SubCategoryId  = new SelectList(sub, "SubCategoryId", "Name");
            ViewBag.CarModelId     = new SelectList(res, "CarModelId", "Name");
            return(View(car));
        }
Esempio n. 3
0
        public JsonResult Rate()
        {
            int  value = int.Parse(Request.Form["value"]);
            int  CarID = int.Parse(Request.Form["id"]);
            Rate rate  = new Rate {
                CarId = CarID, rate1 = value
            };
            var db          = new LocationVoiture.Data.LocationContext();
            var CurrentUser = db.Users.Where(x => x.UserName.Equals(User.Identity.Name)).FirstOrDefault();

            rate.UserId = CurrentUser.UserID;
            serviceRating.addRate(rate);
            serviceRating.commit();
            Car    car = myService.GetById(CarID);
            double s   = serviceRating.avgRate(car);

            return(Json(s));
        }