Exemplo n.º 1
0
        //Get CarUpdate
        public ActionResult CarUpdate(int id)
        {
            User user = (User)Session["LoginUser"];

            CarsRepository     carRepository      = new CarsRepository();
            CarPhotoRepository carPhotoRepository = new CarPhotoRepository();
            var          result      = carRepository.GetByFilter(x => x.UserId == user.Id && x.Id == id).FirstOrDefault();
            var          photoresult = carPhotoRepository.GetByFilter(x => x.CarId == id).FirstOrDefault();
            CarViewModel carView     = new CarViewModel();

            carView.Id          = id;
            carView.Brand       = result.Brand;
            carView.CarPlate    = result.CarPlate;
            carView.CaseType    = result.CaseType;
            carView.Color       = result.Color;
            carView.Engine      = result.Engine;
            carView.EnginePower = result.EnginePower;
            carView.Fuel        = result.Fuel;
            carView.Gear        = result.Gear;
            carView.Km          = result.Km;
            carView.Model       = result.Model;
            carView.Photo       = photoresult.Photo;
            carView.Price       = result.Price;
            carView.Sherry      = result.Sherry;
            carView.Traction    = result.Traction;
            carView.Waranty     = result.Waranty;
            carView.Year        = result.Year;
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult CarAdd(FormCollection model)
        {
            User               user            = (User)Session["LoginUser"];
            CarsRepository     carsRepository  = new CarsRepository();
            CarPhotoRepository photoRepository = new CarPhotoRepository();
            var resultcar = carsRepository.Add(new RCP.Model.Cars
            {
                UserId       = user.Id,
                Brand        = model["Brand"],
                Price        = Convert.ToInt32(model["Price"]),
                Sherry       = model["Sherry"],
                CarPlate     = model["CarPlate"],
                CaseType     = model["CaseType"],
                Color        = model["Color"],
                Engine       = model["Engine"],
                EnginePower  = model["EnginePower"],
                Fuel         = model["Fuel"],
                Gear         = model["Gear"],
                IsDelete     = false,
                Km           = Convert.ToInt32(model["Km"]),
                Model        = model["Model"],
                RegisterDate = DateTime.Now,
                Traction     = model["Traction"],
                Waranty      = model["Waranty"] == "1" ? true : false,
                Year         = Convert.ToDateTime(model["Year"])
            });
            float deger  = Convert.ToInt32(model["Km"]);
            var   result = carsRepository.GetByFilter(x => x.UserId == user.Id && x.Km == deger).FirstOrDefault();

            photoRepository.Add(new RCP.Model.CarPhoto
            {
                Photo        = model["Photo"],
                CarId        = result.Id,
                IsDelete     = false,
                RegisterDate = DateTime.Now
            });
            JsonData     jsondot     = new JsonData();
            string       json        = jsondot.data;
            List <Brand> jsonRequest = JsonConvert.DeserializeObject <List <Brand> >(json);
            // Gelen Değeri Modele Aktardım
            List <Brand>  brand = jsonRequest;
            List <string> marka = new List <string>();

            foreach (var item in brand)
            {
                marka.Add(item.BrandName);
            }
            ViewBag.Markalar  = marka;
            TempData["Mesaj"] = resultcar ? new TempDataDictionary {
                { "class", "alert-success" }, { "Msg", "Kayıt başarıyla eklendi." }
            } : new TempDataDictionary {
                { "class", "alert-danger" }, { "Msg", "Kayıt eklenemedi bilgilerini kontrol et." }
            };
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult CarUpdate(CarViewModel model)
        {
            User               user               = (User)Session["LoginUser"];
            CarsRepository     carsRepository     = new CarsRepository();
            CarPhotoRepository carPhotoRepository = new CarPhotoRepository();
            var result    = carsRepository.GetByFilter(x => x.UserId == user.Id && x.Id == model.Id).FirstOrDefault();
            var resultcar = carsRepository.UpdateCar(new Cars
            {
                Id           = result.Id,
                Brand        = result.Brand,
                CarPlate     = result.CarPlate,
                CaseType     = result.CaseType,
                Color        = result.Color,
                Engine       = result.Engine,
                EnginePower  = result.EnginePower,
                Fuel         = result.Fuel,
                Gear         = result.Gear,
                Km           = result.Km,
                Model        = result.Model,
                Price        = result.Price,
                Sherry       = result.Sherry,
                Traction     = result.Traction,
                Waranty      = result.Waranty,
                Year         = result.Year,
                RegisterDate = DateTime.Now,
                IsDelete     = false
            });
            var carphotoresult = carPhotoRepository.GetByFilter(x => x.CarId == result.Id).FirstOrDefault();

            carPhotoRepository.UpdateCarPhoto(new CarPhoto
            {
                Id    = carphotoresult.Id,
                CarId = result.Id,
                Photo = model.Photo
            });


            TempData["Mesaj"] = resultcar ? new TempDataDictionary {
                { "class", "alert-success" }, { "Msg", "Kayıt başarıyla güncellendi." }
            } : new TempDataDictionary {
                { "class", "alert-danger" }, { "Msg", "Kayıt güncellenemedi bilgilerini kontrol et." }
            };
            return(View());
        }
        // GET: Cars
        public ActionResult Cars()
        {
            AdvertRepository       advertRepository   = new AdvertRepository();
            CarsRepository         carsRepository     = new CarsRepository();
            CarPhotoRepository     carPhotoRepository = new CarPhotoRepository();
            List <AdvertViewModel> advertViews        = new List <AdvertViewModel>();
            var result       = carsRepository.GetAll();
            var resultadvert = advertRepository.GetAll();

            foreach (var item in result)
            {
                advertViews.Add(new AdvertViewModel {
                    Carss = item,
                    Photo = carPhotoRepository.GetByFilterx(x => x.CarId == item.Id).Photo
                });
            }
            foreach (var item in resultadvert)
            {
                advertViews.ForEach(x => x.Adverts = item);
            }

            return(View(advertViews));
        }