public ActionResult Create()
        {
            var viewModel = new PartsFormViewModel {
                Categories = _unitOfWork.Categories.GetAllNonDeleteCategories(),
                Brands     = _unitOfWork.Brands.GetAllBrands()
            };

            return(View(viewModel));
        }
        public ActionResult Update(PartsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _unitOfWork.Categories.GetAllNonDeleteCategories();
                viewModel.Brands     = _unitOfWork.Brands.GetAllBrands();
                return(View("Create", viewModel));
            }
            var part = _unitOfWork.Parts.GetPartsWithPartId(viewModel.Id);

            part.Modify(viewModel.PartName, viewModel.PartDetails, viewModel.BrandId, viewModel.CategoriesId, UpdateImageUpload(viewModel.PartImage, UPLOAD_DIRECTORY, viewModel.ImageUrl));

            _unitOfWork.Complete();
            return(RedirectToAction("PartsList", "Parts"));
        }
        public ActionResult Edit(int id)
        {
            Parts part = _unitOfWork.Parts.GetPartsWithPartId(id);

            var viewModel = new PartsFormViewModel
            {
                Heading      = "Edit part",
                Categories   = _unitOfWork.Categories.GetAllNonDeleteCategories(),
                Brands       = _unitOfWork.Brands.GetAllBrands(),
                PartName     = part.PartName,
                PartDetails  = part.PartDetails,
                Id           = part.Id,
                BrandId      = part.BrandId,
                CategoriesId = part.CategoriesId,
                ImageUrl     = part.PartImageUrl
            };

            return(View("Create", viewModel));
        }
        public ActionResult Create(PartsFormViewModel viewModel, HttpPostedFileBase image)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _unitOfWork.Categories.GetAllNonDeleteCategories();
                viewModel.Brands     = _unitOfWork.Brands.GetAllBrands();
                return(View("Create", viewModel));
            }
            ImageUpload(image);

            var _partsModel = new Parts {
                PartName     = viewModel.PartName,
                PartImageUrl = _imageurl,
                PartDetails  = viewModel.PartDetails,
                CategoriesId = viewModel.CategoriesId,
                BrandId      = viewModel.BrandId
            };

            _unitOfWork.Parts.AddPart(_partsModel);
            _unitOfWork.Complete();
            return(RedirectToAction("PartsList", "Parts"));
        }
        public ActionResult Create(PartsFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = _unitOfWork.Categories.GetAllNonDeleteCategories();
                viewModel.Brands     = _unitOfWork.Brands.GetAllBrands();
                return(View("Create", viewModel));
            }
            ImageUpload(viewModel.PartImage, UPLOAD_DIRECTORY);

            var _partsModel = new Parts
            {
                PartName     = viewModel.PartName,
                PartImageUrl = Path.Combine(UPLOAD_DIRECTORY, viewModel.PartImage.FileName),
                PartDetails  = viewModel.PartDetails,
                CategoriesId = viewModel.CategoriesId,
                BrandId      = viewModel.BrandId
            };

            _unitOfWork.Parts.AddPart(_partsModel);
            _unitOfWork.Complete();
            return(RedirectToAction("PartsList", "Parts"));
        }
 public ActionResult Update(PartsFormViewModel viewModel)
 {
     return(View());
 }