Beispiel #1
0
        // GET: Voiture
        public ActionResult Index()
        {
            CarIndexViewsModel vm = new CarIndexViewsModel
            {
                CarsMakes = GetCarsMakes(),
                Companys  = GetCompanys()
            };

            int idCurrentUser = (int)Session["userId"];

            Session["notifs"] = notificationLogic.ListAllForUser(idCurrentUser).FindAll(n => n.IsRead == 0).Count;

            return(View(vm));
        }
Beispiel #2
0
        public ActionResult AddCar(HttpPostedFileBase CarImage, CarIndexViewsModel vm, int dropdownlistCarsModels, int CompanyId, string Licence_Plate, int Mileage, string Energy)
        {
            CarDTO car = new CarDTO
            {
                Energy_Value  = Energy,
                id_Car_Model  = dropdownlistCarsModels,
                is_Active     = 1,
                is_Available  = 1,
                Licence_Plate = Licence_Plate,
                Mileage       = Mileage,
                Id_User       = (int)Session["userId"],
                Id_Company    = CompanyId
            };

            if (CarImage != null && CarImage.ContentLength > 0)
            {
                try
                {
                    string extension = Path.GetExtension(CarImage.FileName);
                    string filename  = Licence_Plate;

                    string newFile = filename + extension;

                    string path = Path.Combine(Server.MapPath("~/Images/Cars"), newFile);
                    CarImage.SaveAs(path);
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }


            carLogic.AddCar(car);

            return(RedirectToAction("Index"));
        }