Exemple #1
0
        public ActionResult Create([Bind(Include = "Id,DateofPurchase,Status,Quantity,VehicleId,VehicleEquipmentTypeId")] VehicleEquipment vehicleEquipment,
                                   IEnumerable <HttpPostedFileBase> image)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in image)
                {
                    string error;
                    if (!FileHelper.CheckIfFileIsImage(item, out error))
                    {
                        ModelState.AddModelError("", error);
                        ViewBag.VehicleId = new SelectList(DataFilter.GetVehicles(TempData.Peek("Id") + ""), "Id", "Name", vehicleEquipment.VehicleId);
                        ViewBag.VehicleEquipmentTypeId = new SelectList(db.VehicleEquipmentTypes, "Id", "Name", vehicleEquipment.VehicleEquipmentTypeId);
                        return(View(vehicleEquipment));
                    }
                }

                vehicleEquipment.Id = Guid.NewGuid();

                string basePath = Server.MapPath(Constants.VEHICLE_EQUIPMENTS_UPLOAD_BASE_PATH + vehicleEquipment.Id + "/");
                FileHelper.SaveFiles(image, basePath);

                db.VehicleEquipments.Add(vehicleEquipment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.VehicleId = new SelectList(DataFilter.GetVehicles(TempData.Peek("Id") + ""), "Id", "Name", vehicleEquipment.VehicleId);
            ViewBag.VehicleEquipmentTypeId = new SelectList(db.VehicleEquipmentTypes, "Id", "Name", vehicleEquipment.VehicleEquipmentTypeId);
            return(View(vehicleEquipment));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            VehicleEquipment vehicleEquipment = db.VehicleEquipments.Find(id);

            db.VehicleEquipments.Remove(vehicleEquipment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "Id,DateofPurchase,Status,Quantity,VehicleId,VehicleEquipmentTypeId")] VehicleEquipment vehicleEquipment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vehicleEquipment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.VehicleId = new SelectList(DataFilter.GetVehicles(TempData.Peek("Id") + ""), "Id", "Name", vehicleEquipment.VehicleId);
     ViewBag.VehicleEquipmentTypeId = new SelectList(db.VehicleEquipmentTypes, "Id", "Name", vehicleEquipment.VehicleEquipmentTypeId);
     return(View(vehicleEquipment));
 }
Exemple #4
0
        // GET: VehicleEquipments/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VehicleEquipment vehicleEquipment = db.VehicleEquipments.Find(id);

            if (vehicleEquipment == null)
            {
                return(HttpNotFound());
            }
            return(View(vehicleEquipment));
        }
Exemple #5
0
        // GET: VehicleEquipments/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VehicleEquipment vehicleEquipment = db.VehicleEquipments.Find(id);

            if (vehicleEquipment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.VehicleId = new SelectList(DataFilter.GetVehicles(TempData.Peek("Id") + ""), "Id", "Name", vehicleEquipment.VehicleId);
            ViewBag.VehicleEquipmentTypeId = new SelectList(db.VehicleEquipmentTypes, "Id", "Name", vehicleEquipment.VehicleEquipmentTypeId);
            return(View(vehicleEquipment));
        }
Exemple #6
0
        // GET: VehicleEquipments/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VehicleEquipment vehicleEquipment = db.VehicleEquipments.Find(id);

            if (vehicleEquipment == null)
            {
                return(HttpNotFound());
            }

            string basePath = Server.MapPath(Constants.VEHICLE_EQUIPMENTS_UPLOAD_BASE_PATH + vehicleEquipment.Id + "/");

            if (Directory.Exists(basePath))
            {
                TempData["Images"] = FileHelper.GetImages(vehicleEquipment.Id + "", basePath);
            }

            return(View(vehicleEquipment));
        }