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)); }
public ActionResult GetAllParentCategories() { CarShopModel carShopModel = new CarShopModel(); carShopModel.Categorys = slh.GetAllParentCategories(); return(new JsonResultHelper(carShopModel.Categorys, JsonRequestBehavior.AllowGet)); }
public ActionResult AdvertiseCar() { _selectListHelper = new SelectListHelper(); var newCar = new CarShopModel(); newCar.Categorys = slh.GetAllParentCategory(); return(View(newCar)); }
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)); }
public ActionResult DeleteCarAdvertisement(int id, CarShopModel carShopModel) { try { var advetisementCategory = carShopModel.Title; _carShopSystem.DeleteCar(id, advetisementCategory); } catch (Exception) { throw; } return(View()); }
public ActionResult EditCarAdvertisement(CarShopModel carShopModel) { try { if (carShopModel != null) { _carShopSystem.EditCar(CarShopHelper.EntityToModel(carShopModel)); } } catch (Exception) { throw; } return(RedirectToAction("CarView")); }
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); }
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; } }
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 }); } }
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); }