public ActionResult Edit(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var item = _unitOfWork.PartsSubCategory.GetByID(Convert.ToInt32(id));
                PartsSubCategoryViewModel  partsSubCategoryViewModel  = new PartsSubCategoryViewModel();
                PartsSubCategoryRepository partsSubCategoryRepository = new PartsSubCategoryRepository(new AutoSolutionContext());
                partsSubCategoryViewModel.PartsProductsSubCategoryId    = item.PartsProductsSubCategoryId;
                partsSubCategoryViewModel.PartsProductsSubCategoryName  = item.PartsProductsSubCategoryName;
                partsSubCategoryViewModel.SelectedPartsProductsCategory = item.PartsProductsCategoryId.ToString();
                partsSubCategoryViewModel.PartsProductsCategoryList     = partsSubCategoryRepository.GetPartsProductCategoryDropDown();

                if (partsSubCategoryViewModel != null)
                {
                    return(PartialView("_EditPartsSubCategory", partsSubCategoryViewModel));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public ActionResult Edit(string id)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var item          = _unitOfWork.PartsProducts.GetByID(Convert.ToInt32(id));
                var VManufacturer = _unitOfWork.VehicleManufacturer.GetByID(item.VehicleModel.VehicleManufacturerId);
                var VModel        = _unitOfWork.VehicleModel.GetByID(item.VehicleModel.VehicleModelId);
                var PSUbCategory  = _unitOfWork.PartsSubCategory.GetByID(item.PartsProductsSubCategoryId);
                var PCategory     = _unitOfWork.PartsProductsCategory.GetByID(item.PartsProductsSubCategory.PartsProductsCategoryId);
                var PManufacturer = _unitOfWork.PartsProductManufacturer.GetByID(item.PartsProductManufacturer.PartsProductManufacturerId);
                VehicleModelRepository             vehicleModelRepository             = new VehicleModelRepository(new AutoSolutionContext());
                PartsSubCategoryRepository         partsSubCategoryRepository         = new PartsSubCategoryRepository(new AutoSolutionContext());
                TransmissionTypeRepository         transmissionTypeRepository         = new TransmissionTypeRepository(new AutoSolutionContext());
                VehicleEngineTypeRepository        vehicleEngineTypeRepository        = new VehicleEngineTypeRepository(new AutoSolutionContext());
                PartsProductManufacturerRepository partsProductManufacturerRepository = new PartsProductManufacturerRepository(new AutoSolutionContext());

                PartsProductsViewModel partsProductsViewModel = new PartsProductsViewModel();
                partsProductsViewModel.PartsProductId   = item.PartsProductId;
                partsProductsViewModel.EndYear          = item.EndYear;
                partsProductsViewModel.startYear        = item.startYear;
                partsProductsViewModel.PartsProductName = item.PartsProductName;
                partsProductsViewModel.LongDescription  = item.LongDescription;
                partsProductsViewModel.ShortDescription = item.ShortDescription;
                partsProductsViewModel.UnitPrice        = item.UnitPrice;


                partsProductsViewModel.VehicleManufacturerList      = vehicleModelRepository.GetVehicleManufacturerDropDown();
                partsProductsViewModel.VehicleModelList             = vehicleModelRepository.GetVehicleModelDropDown();
                partsProductsViewModel.PartsProductsCategoryList    = partsSubCategoryRepository.GetPartsProductCategoryDropDown();
                partsProductsViewModel.PartsProductsSubCategoryList = partsSubCategoryRepository.GetPartsProductSubCategoryDropDown();
                partsProductsViewModel.PartProductManufacturerList  = partsProductManufacturerRepository.GetPPManufacturerDropDown();


                partsProductsViewModel.SelectedManufacturer            = VManufacturer.VehicleManufacturerId;
                partsProductsViewModel.SelectedModel                   = VModel.VehicleModelId;
                partsProductsViewModel.SelectedPartsProductCategory    = PCategory.PartsProductsCategoryId.ToString();
                partsProductsViewModel.SelectedPartsProductSubCategory = PSUbCategory.PartsProductsSubCategoryId.ToString();
                partsProductsViewModel.SelectedPartProductManufacturer = PManufacturer.PartsProductManufacturerId.ToString();
                partsProductsViewModel.SelectedModel                   = item.VehicleModelId;

                partsProductsViewModel.PartProductImagesList = item.PartProductImages.ToList();
                if (partsProductsViewModel != null)
                {
                    return(PartialView("_EditPartsProduct", partsProductsViewModel));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public ActionResult AddNew(PartsSubCategoryViewModel partsSubCategoryViewModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string str = partsSubCategoryViewModel.PartsProductsSubCategoryName;
             PartsSubCategoryRepository partsSubCategoryRepository = new PartsSubCategoryRepository(new AutoSolutionContext());
             bool IsExist = partsSubCategoryRepository.isExist(partsSubCategoryViewModel.PartsProductsSubCategoryName);
             if (!IsExist)
             {
                 PartsProductsSubCategory partsProductsSubCategory = new PartsProductsSubCategory();
                 partsProductsSubCategory.PartsProductsSubCategoryName = partsSubCategoryViewModel.PartsProductsSubCategoryName;
                 partsProductsSubCategory.PartsProductsCategoryId      = Convert.ToInt32(partsSubCategoryViewModel.SelectedPartsProductsCategory);
                 _unitOfWork.PartsSubCategory.Add(partsProductsSubCategory);
                 _unitOfWork.Complete();
                 _unitOfWork.Dispose();
                 return(RedirectToAction("GetPartsProductSubCategory"));
             }
             else
             {
                 return(RedirectToAction("GetPartsProductSubCategory"));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(View());
 }