public ActionResult AddVehicleConfirm(VehicleOperationView vov, HttpPostedFileBase file1)
        {
            if (ModelState.IsValid)
            {
                unitOfWork = new EFUnitOfWork(db);

                var entity = Mapper.Map <VehicleModalViewModel, Vehicle>(vov.VehicleModalViewModel);

                if (file1 != null)
                {
                    entity.ImageUrl = "~/Images/VehicleImages/" + entity.Name + entity.Year + ".png";;
                    string path = Path.Combine(Server.MapPath(entity.ImageUrl));
                    file1.SaveAs(path);
                }

                entity.Rented = false;

                unitOfWork.GetRepository <Vehicle>().Add(entity);

                unitOfWork.SaveChanges();

                unitOfWork.Dispose();
            }


            return(RedirectToAction("Index"));
        }
        public ActionResult EditVehicleConfirm(VehicleOperationView vov, HttpPostedFileBase file1)
        {
            if (ModelState.IsValid)
            {
                unitOfWork = new EFUnitOfWork(db);

                var entity = unitOfWork.GetRepository <Vehicle>().GetById(vov.VehicleModalViewModel.Id);

                string imageUrl = entity.ImageUrl;

                Mapper.Map(vov.VehicleModalViewModel, entity);

                entity.ImageUrl = imageUrl;
                if (file1 != null)
                {
                    string fullPath = Request.MapPath(entity.ImageUrl);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                    entity.ImageUrl = "~/Images/VehicleImages/" + entity.Name + ".png";;
                    string path = Path.Combine(Server.MapPath(entity.ImageUrl));
                    file1.SaveAs(path);
                }

                unitOfWork.GetRepository <Vehicle>().Update(entity);

                unitOfWork.SaveChanges();

                unitOfWork.Dispose();
            }

            return(RedirectToAction("VehicleEditModal", new { id = vov.VehicleModalViewModel.Id }));
        }
        public PartialViewResult VehicleEditModal(int?id)
        {
            unitOfWork = new EFUnitOfWork(db);
            var modal = unitOfWork.GetRepository <Vehicle>().GetById((int)id);

            VehicleOperationView vov = new VehicleOperationView();

            vov.VehicleModalViewModel = Mapper.Map <Vehicle, VehicleModalViewModel>(modal);

            var types = unitOfWork.GetRepository <Type>().GetAll().Select(t => new SelectListItem()
            {
                Value = t.Id.ToString(),
                Text  = t.Name
            }).ToList();

            var brands = unitOfWork.GetRepository <Brand>().GetAll().Select(b => new SelectListItem()
            {
                Value = b.Id.ToString(),
                Text  = b.Name
            }).ToList();

            var models = unitOfWork.GetRepository <Model>().GetAll().Select(m => new SelectListItem()
            {
                Value = m.Id.ToString(),
                Text  = m.Name
            }).ToList();

            vov.Types = new SelectList(types, "Value", "Text", vov.VehicleModalViewModel.TypeId);

            vov.Brands = new SelectList(brands, "Value", "Text", vov.VehicleModalViewModel.BrandId);

            vov.Models = new SelectList(models, "Value", "Text", vov.VehicleModalViewModel.ModelId);

            unitOfWork.Dispose();

            return(PartialView("_VehicleEditPartialView", vov));
        }