コード例 #1
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
 public ActionResult AdvertiseCar(CarShopModel carShopModel)
 {
     try
     {
         carShopModel.Categorys = slh.GetAllParentCategories();
         var childCategories = _carShopSystem.GetChildCategorysById(carShopModel.ParentCategoryId);
         carShopModel.ChildCategorys = childCategories.Select(x => new SelectListItem
         {
             Value = x.ChildCategoryId.ToString(),
             Text  = x.ChildCategoryName
         }).ToList();
         if (carShopModel != null)
         {
             var newCar = CarShopHelper.EntityToModel(carShopModel);
             if (carShopModel.Files != null && carShopModel.Files.Any(x => x != null))
             {
                 newCar.Files = UploadPictures(carShopModel).ToList();
             }
             _carShopSystem.CreateNewCar(newCar);
             return(RedirectToAction("CarView"));
         }
     }
     catch (Exception e)
     {
         log.Error(e.ToString());
         throw;
     }
     return(View(carShopModel));
 }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
        public ActionResult GetAllParentCategories()
        {
            CarShopModel carShopModel = new CarShopModel();

            carShopModel.Categorys = slh.GetAllParentCategories();
            return(new JsonResultHelper(carShopModel.Categorys, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
        public ActionResult AdvertiseCar()
        {
            _selectListHelper = new SelectListHelper();
            var newCar = new CarShopModel();

            newCar.Categorys = slh.GetAllParentCategory();
            return(View(newCar));
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
        public ActionResult ChildCategorysFromParen(int id)
        {
            var advertise     = new CarShopModel();
            var childCategory = _carShopSystem.GetChildCategorysById(id);

            advertise.ChildCategorys = childCategory.Select(x => new SelectListItem
            {
                Text  = x.ChildCategoryName.ToString(),
                Value = x.ChildCategoryId.ToString()
            }).ToList();
            //JsonResultHelper är en custom json camelcase helper, som serializes data via Json gör om och följer camelCase varianten.
            return(new JsonResultHelper(advertise.ChildCategorys, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
 public ActionResult DeleteCarAdvertisement(int id, CarShopModel carShopModel)
 {
     try
     {
         var advetisementCategory = carShopModel.Title;
         _carShopSystem.DeleteCar(id, advetisementCategory);
     }
     catch (Exception)
     {
         throw;
     }
     return(View());
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
 public ActionResult EditCarAdvertisement(CarShopModel carShopModel)
 {
     try
     {
         if (carShopModel != null)
         {
             _carShopSystem.EditCar(CarShopHelper.EntityToModel(carShopModel));
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(RedirectToAction("CarView"));
 }
コード例 #7
0
        public static CarShopEntity EntityToModel(CarShopModel carEntity)
        {
            var model = new CarShopEntity();

            model.AdvertisementId   = carEntity.AdvertisementId;
            model.CarModel          = carEntity.CarModel;
            model.City              = carEntity.City;
            model.Description       = carEntity.Description;
            model.Fuel              = carEntity.Fuel;
            model.GearBox           = carEntity.GearBox;
            model.ManufacturingYear = DateTime.Now;
            model.Mileage           = carEntity.Mileage;
            model.ModelYear         = carEntity.ModelYear;
            model.PostalNumber      = carEntity.PostalNumber;
            model.Price             = carEntity.Price;
            model.Title             = carEntity.Title;
            model.AdvertisementDay  = carEntity.AdvertisementDay;
            model.ChildCategory     = carEntity.ChildCategoryName;
            return(model);
        }
コード例 #8
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
        public ActionResult FeaturedCars(CarShopModel carModel, string Id)
        {
            try
            {
                //var carModel = new CarShopModel();
                var carList = _carShopSystem.ListExistingCars();
                //var carsToBeFeatured = _carShopSystem.GetFeaturedCars(carModel.IsFeatured);
                var advertisementId = carList.Select(x => x.AdvertisementId).ToList();
                var pictures        = _carShopSystem.GetFeaturedPictures(advertisementId);
                //carsToBeFeatured.Select(x => x.Files == pictures);
                carList.Where(x => x.Files == pictures);

                var transformed = CarShopHelper.Transform(carList);
                return(PartialView(transformed));
            }
            catch (Exception e)
            {
                log.Error(e.ToString());
                throw;
            }
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: Fowgel/AutoShop
        private IEnumerable <PictureEntity> UploadPictures(CarShopModel carShopModel)
        {
            var fileDirectory = ConfigurationManager.AppSettings["Path"].ToString();

            foreach (var file in carShopModel.Files)
            {
                var guid             = Guid.NewGuid();
                var fileType         = Path.GetExtension(file.FileName);
                var fileName         = $"{guid}{fileType}";
                var originalFileName = file.FileName;
                var filePath         = Path.Combine(fileDirectory, fileName);

                file.SaveAs(filePath);

                yield return(new PictureEntity
                {
                    AdvertisementId = 0,
                    PictureGuid = guid,
                    PictureGuidName = fileName,
                    PictureName = originalFileName
                });
            }
        }
コード例 #10
0
        public static CarShopModel ModelToEntity(CarShopEntity carEntity)
        {
            var model = new CarShopModel();

            model.AdvertisementId   = carEntity.AdvertisementId;
            model.CarModel          = carEntity.CarModel;
            model.City              = carEntity.City;
            model.Description       = carEntity.Description;
            model.Fuel              = carEntity.Fuel;
            model.GearBox           = carEntity.GearBox;
            model.ManufacturingYear = DateTime.Now;
            model.Mileage           = carEntity.Mileage;
            model.ModelYear         = carEntity.ModelYear;
            model.PostalNumber      = carEntity.PostalNumber;
            model.Price             = carEntity.Price;
            model.Title             = carEntity.Title;
            model.AdvertisementDay  = carEntity.AdvertisementDay;
            model.ChildCategoryName = carEntity.ChildCategory;
            model.Fileings          = carEntity.Files?.Select(p => p.PictureGuidName).ToList();


            return(model);
        }