Beispiel #1
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));
        }
Beispiel #2
0
 public ActionResult Create(Car car)
 {
     if (ModelState.IsValid)
     {
         myService.Add(car);
         myService.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(car));
 }