Esempio n. 1
0
        public VechicleViewModel GetInventorysById(int id)
        {
            VechicleViewModel temp = Inventorys.Where(p => p.Id == id).Include("Mdles").Include("Typs").Include("BodyStyles")
                                     .Include("Transmissions").Include("Colors").Include("Interiors")
                                     .Include("PurchaseTypes").Select(i => new VechicleViewModel
            {
                InventoryId    = i.Id,
                Make           = i.Mdles.Makes.MakeName,
                Model          = i.Mdles.ModelName,
                Type           = i.Typs.TypeName,
                BodyStyle      = i.BodyStyles.BodyStyleName,
                Year           = i.Year,
                Transmission   = i.Transmissions.TransmissionName,
                Color          = i.Colors.ColorName,
                Interior       = i.Interiors.InteriorName,
                Mileage        = i.Mileage,
                VIN            = i.VIN,
                MSRP           = i.MSRP,
                SalesPrice     = i.SalesPrice,
                Description    = i.Description,
                Picture        = i.Picture,
                FeatureVehicle = i.FeatureVehicle,
                StillAvailable = i.PurchaseTypeId == null ? "Yes" : "No"
            }).FirstOrDefault();

            return(temp);
        }
Esempio n. 2
0
        public IEnumerable <VechicleViewModel> GetAll()
        {
            List <VechicleViewModel> repo = new List <VechicleViewModel>();



            foreach (var item in _inventorys)
            {
                VechicleViewModel vechicle = new VechicleViewModel();
                vechicle.InventoryId    = item.Id;
                vechicle.Make           = GetMakesById(_models.Where(id => id.MdleId == item.MdleId).SingleOrDefault().MakeId).MakeName;
                vechicle.Model          = _models.Where(id => id.MdleId == item.MdleId).SingleOrDefault().ModelName;
                vechicle.Type           = _types.Where(id => id.TypId == item.TypId).SingleOrDefault().TypeName;
                vechicle.BodyStyle      = _bodyStyles.Where(id => id.BodyStyleId == item.BodyStyleId).SingleOrDefault().BodyStyleName;
                vechicle.Year           = item.Year;
                vechicle.Transmission   = _transimissions.Where(id => id.TransmissionId == item.TransmissionId).SingleOrDefault().TransmissionName;
                vechicle.Color          = _colors.Where(id => id.ColorId == item.ColorId).SingleOrDefault().ColorName;
                vechicle.Interior       = _interiors.Where(id => id.InteriorId == item.InteriorId).SingleOrDefault().InteriorName;
                vechicle.Mileage        = item.Mileage;
                vechicle.VIN            = item.VIN;
                vechicle.MSRP           = item.MSRP;
                vechicle.SalesPrice     = item.SalesPrice;
                vechicle.Description    = item.Description;
                vechicle.Picture        = item.Picture;
                vechicle.FeatureVehicle = item.FeatureVehicle;
                vechicle.StillAvailable = item.PurchaseTypeId == null ? "Yes" : "No";
                vechicle.SalesId        = item.SalesPersonId;
                vechicle.PurchasedPrice = item.PurchasePrice;


                repo.Add(vechicle);
            }

            return(repo);
        }
Esempio n. 3
0
        public IHttpActionResult GetVechicleById(int id)
        {
            var repo = CarDearlershipRespoFacotory.GetRepository();
            VechicleViewModel listings = repo.GetInventorysById(id);


            return(Json(listings, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
Esempio n. 4
0
        public void EditVechicle(VechicleViewModel vechicle)
        {
            var editVehicle = Inventorys.Include("Mdles").Include("Typs").Include("BodyStyles")
                              .Include("Transmissions").Include("Colors").Include("Interiors")
                              .Include("PurchaseTypes").FirstOrDefault(p => p.Id == vechicle.InventoryId);

            editVehicle.Id           = vechicle.InventoryId;
            editVehicle.Mdles.MakeId = Makes.FirstOrDefault(p => p.MakeName == vechicle.Make).MakeId;
            editVehicle.MdleId       = Models.FirstOrDefault(p => p.ModelName == vechicle.Model).MdleId;

            editVehicle.BodyStyleId    = BodyStyles.FirstOrDefault(p => p.BodyStyleName == vechicle.BodyStyle).BodyStyleId;
            editVehicle.ColorId        = Colors.SingleOrDefault(p => p.ColorName == vechicle.Color).ColorId;
            editVehicle.TypId          = Typs.SingleOrDefault(p => p.TypeName == vechicle.Type).TypId;
            editVehicle.Year           = vechicle.Year;
            editVehicle.TransmissionId = Transmissions.SingleOrDefault(p => p.TransmissionName == vechicle.Transmission).TransmissionId;
            editVehicle.InteriorId     = Interiors.FirstOrDefault(p => p.InteriorName == vechicle.Interior).InteriorId;
            editVehicle.Mileage        = vechicle.Mileage;
            editVehicle.VIN            = vechicle.VIN;
            editVehicle.MSRP           = vechicle.MSRP;
            editVehicle.SalesPrice     = vechicle.SalesPrice;
            editVehicle.Description    = vechicle.Description;

            editVehicle.FeatureVehicle = vechicle.FeatureVehicle;
            if (editVehicle.Picture != null)
            {
                var    oldFile = editVehicle.Picture;
                string path    = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                              Path.GetFileName(oldFile));
                File.Delete(path);
            }

            if (vechicle.File != null && vechicle.File.ContentLength > 0)
            {
                string[] fileName = vechicle.File.FileName.Split('.');
                string   newName  = "inventory-" + editVehicle.Id + "." + fileName.Last();


                string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                           Path.GetFileName(newName));

                vechicle.File.SaveAs(path);
                editVehicle.Picture = newName;
            }



            (this).SaveChanges();
        }
Esempio n. 5
0
        public ActionResult EditVehicle(VechicleViewModel editVechicle, string submit)
        {
            switch (submit)
            {
            case "Save":
                CarDearlershipRespoFacotory.GetRepository().EditVechicle(editVechicle);
                break;

            case "Delete":
                CarDearlershipRespoFacotory.GetRepository().DeleteVehicle(editVechicle.InventoryId);
                break;
            }



            return(RedirectToAction("Vehicles"));
        }
Esempio n. 6
0
        public void EditVechicle(VechicleViewModel vechicle)
        {
            Inventory editVehicle = _inventorys.FirstOrDefault(p => p.Id == vechicle.InventoryId);

            _inventorys.Remove(editVehicle);
            editVehicle.Id = vechicle.InventoryId;

            editVehicle.MdleId = _models.FirstOrDefault(p => p.ModelName == vechicle.Model).MdleId;

            editVehicle.BodyStyleId    = _bodyStyles.FirstOrDefault(p => p.BodyStyleName == vechicle.BodyStyle).BodyStyleId;
            editVehicle.ColorId        = _colors.SingleOrDefault(p => p.ColorName == vechicle.Color).ColorId;
            editVehicle.TypId          = _types.SingleOrDefault(p => p.TypeName == vechicle.Type).TypId;
            editVehicle.Year           = vechicle.Year;
            editVehicle.TransmissionId = _transimissions.SingleOrDefault(p => p.TransmissionName == vechicle.Transmission).TransmissionId;
            editVehicle.InteriorId     = _interiors.FirstOrDefault(p => p.InteriorName == vechicle.Interior).InteriorId;
            editVehicle.Mileage        = vechicle.Mileage;
            editVehicle.VIN            = vechicle.VIN;
            editVehicle.MSRP           = vechicle.MSRP;
            editVehicle.SalesPrice     = vechicle.SalesPrice;
            editVehicle.Description    = vechicle.Description;

            editVehicle.FeatureVehicle = vechicle.FeatureVehicle;
            if (editVehicle.Picture != null)
            {
                var    oldFile = editVehicle.Picture;
                string path    = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                              Path.GetFileName(oldFile));
                File.Delete(path);
            }

            if (vechicle.File != null && vechicle.File.ContentLength > 0)
            {
                string[] fileName = vechicle.File.FileName.Split('.');
                string   newName  = "inventory-" + editVehicle.Id + "." + fileName.Last();


                string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                           Path.GetFileName(newName));

                vechicle.File.SaveAs(path);
                editVehicle.Picture = newName;
            }

            _inventorys.Add(editVehicle);
        }
        public ActionResult Details(int id)
        {
            VechicleViewModel repo = CarDearlershipRespoFacotory.GetRepository().GetInventorysById(id);

            return(View(repo));
        }