Beispiel #1
0
        public ActionResult Index()
        {
            CarViewModel model = new CarViewModel();

            var carRepo           = GuildRepositoryFactory.GetRepository();
            var makesRepo         = MakeFactory.GetRepository();
            var modelRepo         = ModelFactory.GetRepository();
            var typesRepo         = ConditionFactory.GetRepository();
            var bodyStylesRepo    = BodyStyleFactory.GetRepository();
            var transmissionsRepo = TransmissionFactory.GetRepository();
            var extColorsRepo     = ExteriorColorFactory.GetRepository();
            var intColorsRepo     = InteriorColorFactory.GetRepository();

            List <Car> carList = carRepo.GetAllCars();

            List <CarViewModel> carVMList = carList.Select(x => new CarViewModel
            {
                CarID         = x.CarID,
                MakeID        = x.MakeID,
                MakeName      = makesRepo.GetMakeById(x.MakeID).MakeName,
                ModelID       = x.ModelID,
                ModelName     = modelRepo.GetModelById(x.ModelID).ModelName,
                Year          = x.Year,
                MSRP          = x.MSRP,
                SalePrice     = x.SalePrice,
                ImageFileName = x.Photo
            }).ToList();

            /*foreach (var car in carList)
             * {
             * }*/

            return(View(carVMList));
        }
Beispiel #2
0
        public ActionResult Add()
        {
            var model = new CarAddViewModel();

            var carRepo           = GuildRepositoryFactory.GetRepository();
            var makesRepo         = MakeFactory.GetRepository();
            var modelRepo         = ModelFactory.GetRepository();
            var typesRepo         = ConditionFactory.GetRepository();
            var bodyStylesRepo    = BodyStyleFactory.GetRepository();
            var transmissionsRepo = TransmissionFactory.GetRepository();
            var extColorsRepo     = ExteriorColorFactory.GetRepository();
            var intColorsRepo     = InteriorColorFactory.GetRepository();

            CarAddViewModel viewModel = new CarAddViewModel
            {
                Makes          = makesRepo.GetMakes(),
                Models         = modelRepo.GetModels(),
                Types          = typesRepo.GetConditions(),
                BodyStyles     = bodyStylesRepo.GetBodyStyles(),
                Transmissions  = transmissionsRepo.GetTransmissions(),
                ExteriorColors = extColorsRepo.GetExteriorColors(),
                InteriorColors = intColorsRepo.GetInteriorColors()
            };

            return(View(viewModel));
        }
Beispiel #3
0
        public ActionResult Details(int id)
        {
            CarViewModel carViewModel = new CarViewModel();

            var carRepo           = GuildRepositoryFactory.GetRepository();
            var makesRepo         = MakeFactory.GetRepository();
            var modelRepo         = ModelFactory.GetRepository();
            var typesRepo         = ConditionFactory.GetRepository();
            var bodyStylesRepo    = BodyStyleFactory.GetRepository();
            var transmissionsRepo = TransmissionFactory.GetRepository();
            var extColorsRepo     = ExteriorColorFactory.GetRepository();
            var intColorsRepo     = InteriorColorFactory.GetRepository();
            var transactionRepo   = TransactionFactory.GetRepository();

            var carsInStock = carRepo.GetAllCars();

            var isInStock = carsInStock.Where(x => x.CarID == id).Select(x => x.IsInStock).FirstOrDefault();

            if (isInStock)
            {
                carViewModel.IsBought = true;
            }

            var carvm = carRepo.GetCarById(id);

            carViewModel.CarID             = carvm.CarID;
            carViewModel.Year              = carvm.Year;
            carViewModel.Make              = new Make();
            carViewModel.Make.MakeID       = carvm.MakeID;
            carViewModel.MakeName          = makesRepo.GetMakeById(carvm.MakeID).MakeName;
            carViewModel.Model             = new Model();
            carViewModel.Model.ModelID     = carvm.ModelID;
            carViewModel.ModelName         = modelRepo.GetModelById(carvm.ModelID).ModelName;
            carViewModel.BodyStyle         = new BodyStyle();
            carViewModel.BodyStyleID       = carvm.BodyStyleID;
            carViewModel.BodyStyleName     = bodyStylesRepo.GetBodyStyleById(carvm.BodyStyleID).BodyStyleName;
            carViewModel.Transmission      = new Transmission();
            carViewModel.TransmissionID    = carvm.TransmissionID;
            carViewModel.TransmissionType  = transmissionsRepo.GetTransmissionById(carvm.TransmissionID).TransmissionType;
            carViewModel.ExteriorColor     = new ExteriorColor();
            carViewModel.ExteriorColorID   = carvm.ExteriorColorID;
            carViewModel.ExteriorColorName = extColorsRepo.GetExteriorColorById(carvm.ExteriorColorID).Color;
            carViewModel.InteriorColor     = new InteriorColor();
            carViewModel.InteriorColorID   = carvm.InteriorColorID;
            carViewModel.InteriorColorName = intColorsRepo.GetInteriorColorById(carvm.InteriorColorID).Color;
            carViewModel.Mileage           = carvm.Mileage;
            carViewModel.VIN           = carvm.VIN;
            carViewModel.SalePrice     = carvm.SalePrice;
            carViewModel.MSRP          = carvm.MSRP;
            carViewModel.ImageFileName = carvm.Photo;
            carViewModel.Description   = carvm.Description;


            return(View(carViewModel));
        }
Beispiel #4
0
        public ActionResult Edit(int id)
        {
            var carViewModel = new CarEditViewModel();

            var carRepo           = GuildRepositoryFactory.GetRepository();
            var makesRepo         = MakeFactory.GetRepository();
            var modelRepo         = ModelFactory.GetRepository();
            var typesRepo         = ConditionFactory.GetRepository();
            var bodyStylesRepo    = BodyStyleFactory.GetRepository();
            var transmissionsRepo = TransmissionFactory.GetRepository();
            var extColorsRepo     = ExteriorColorFactory.GetRepository();
            var intColorsRepo     = InteriorColorFactory.GetRepository();

            var carvm = carRepo.GetCarById(id);

            carViewModel.CarID            = carvm.CarID;
            carViewModel.Year             = carvm.Year;
            carViewModel.Make             = new Make();
            carViewModel.Makes            = makesRepo.GetMakes();
            carViewModel.MakesID          = carvm.MakeID;
            carViewModel.Model            = new Model();
            carViewModel.Models           = modelRepo.GetModels();
            carViewModel.ModelsID         = carvm.ModelID;
            carViewModel.Condition        = new Condition();
            carViewModel.ConditionTypes   = typesRepo.GetConditions();
            carViewModel.ConditionTypesID = carvm.ConditionID;
            carViewModel.BodyStyle        = new BodyStyle();
            carViewModel.BodyStyles       = bodyStylesRepo.GetBodyStyles();
            carViewModel.BodyStylesID     = carvm.BodyStyleID;
            carViewModel.Transmission     = new Transmission();
            carViewModel.Transmissions    = transmissionsRepo.GetTransmissions();
            carViewModel.TransmissionsID  = carvm.TransmissionID;
            carViewModel.ExteriorColor    = new ExteriorColor();
            carViewModel.ExteriorColors   = extColorsRepo.GetExteriorColors();
            carViewModel.ExteriorColorsID = carvm.ExteriorColorID;
            carViewModel.InteriorColor    = new InteriorColor();
            carViewModel.InteriorColors   = intColorsRepo.GetInteriorColors();
            carViewModel.InteriorColorsID = carvm.InteriorColorID;
            carViewModel.Mileage          = carvm.Mileage;
            carViewModel.VIN           = carvm.VIN;
            carViewModel.SalePrice     = carvm.SalePrice;
            carViewModel.MSRP          = carvm.MSRP;
            carViewModel.ImageFileName = carvm.Photo;
            carViewModel.Description   = carvm.Description;

            return(View(carViewModel));
        }
Beispiel #5
0
        public IEnumerable <Car> Search(ListingSearchParameters parameters)
        {
            List <Car> searchList        = new List <Car>();
            List <Car> searchList2       = new List <Car>();
            var        makesRepo         = MakeFactory.GetRepository();
            var        modelRepo         = ModelFactory.GetRepository();
            var        typesRepo         = ConditionFactory.GetRepository();
            var        bodyStylesRepo    = BodyStyleFactory.GetRepository();
            var        transmissionsRepo = TransmissionFactory.GetRepository();
            var        extColorsRepo     = ExteriorColorFactory.GetRepository();
            var        intColorsRepo     = InteriorColorFactory.GetRepository();

            searchList = cars;

            if (!string.IsNullOrEmpty(parameters.Make)) //FYI: we do not have a make null
            {
                if (parameters.Mileage == "used")
                {
                    searchList = cars.Where(x => x.ConditionID == 2 && makesRepo.GetMakeById(x.MakeID).MakeName.Contains(parameters.Make.ToLower())).ToList();
                }
                else if (parameters.Mileage == "new")
                {
                    searchList = cars.Where(x => x.ConditionID == 1 && makesRepo.GetMakeById(x.MakeID).MakeName.ToLower().Contains(parameters.Make.ToLower())).ToList();
                }
                else if (parameters.OnSale == "true")
                {
                    searchList = cars.Where(x => x.OnSale == true && makesRepo.GetMakeById(x.MakeID).MakeName.ToLower().Contains(parameters.Make.ToLower())).ToList();
                }
                else
                {
                    searchList = cars.Where(x => makesRepo.GetMakeById(x.MakeID).MakeName.ToLower().Contains(parameters.Make.ToLower())).ToList();
                }
            }

            if (!string.IsNullOrEmpty(parameters.Model)) //FYI: we do not have a model null
            {
                if (parameters.Mileage == "used")
                {
                    searchList = cars.Where(x => x.ConditionID == 2 && modelRepo.GetModelById(x.ModelID).ModelName.ToLower().Contains(parameters.Model.ToLower())).ToList();
                }
                else if (parameters.Mileage == "new")
                {
                    searchList = cars.Where(x => x.ConditionID == 1 && modelRepo.GetModelById(x.ModelID).ModelName.ToLower().Contains(parameters.Model.ToLower())).ToList();
                }
                else if (parameters.OnSale == "true")
                {
                    searchList = cars.Where(x => x.OnSale == true && modelRepo.GetModelById(x.ModelID).ModelName.ToLower().Contains(parameters.Model.ToLower())).ToList();
                }
                else
                {
                    searchList = cars.Where(x => modelRepo.GetModelById(x.ModelID).ModelName.ToLower().Contains(parameters.Model.ToLower())).ToList();
                }
            }

            searchList2 = searchList;

            if (!string.IsNullOrEmpty(parameters.MinPrice) || !string.IsNullOrEmpty(parameters.MaxPrice))
            {
                int resultMinPrice;
                int.TryParse(parameters.MinPrice, out resultMinPrice);
                int resultMaxPrice;
                int.TryParse(parameters.MaxPrice, out resultMaxPrice);
                searchList = searchList2.Where(x => x.SalePrice >= resultMinPrice && x.SalePrice <= resultMaxPrice).ToList();
            }

            if (parameters.MinYear != "Any" && parameters.MaxYear != "Any")
            {
                int resultMinYear;
                int.TryParse(parameters.MinYear, out resultMinYear);
                int resultMaxYear;
                int.TryParse(parameters.MaxYear, out resultMaxYear);

                searchList = searchList2.Where(x => x.Year >= resultMinYear && x.Year <= resultMaxYear).ToList();
            }

            if (parameters.MinYear != "Any" && parameters.MaxYear == "Any")
            {
                int resultMinYear;
                int.TryParse(parameters.MinYear, out resultMinYear);

                searchList = searchList2.Where(x => x.Year >= resultMinYear).ToList();
            }

            if (parameters.MinYear == "Any" && parameters.MaxYear != "Any")
            {
                int resultMaxYear;
                int.TryParse(parameters.MaxYear, out resultMaxYear);

                searchList = searchList2.Where(x => x.Year <= resultMaxYear).ToList();
            }

            List <Car> carsSearched = new List <Car>();

            foreach (var car in searchList)
            {
                car.Model                         = new Model();
                car.Model.ModelID                 = car.ModelID;
                car.Model.ModelName               = modelRepo.GetModelById(car.ModelID).ModelName;
                car.Make                          = new Make();
                car.Make.MakeID                   = car.MakeID;
                car.Make.MakeName                 = makesRepo.GetMakeById(car.MakeID).MakeName;
                car.BodyStyle                     = new BodyStyle();
                car.BodyStyle.BodyStyleID         = car.BodyStyleID;
                car.BodyStyle.BodyStyleName       = bodyStylesRepo.GetBodyStyleById(car.BodyStyleID).BodyStyleName;
                car.Transmission                  = new Transmission();
                car.Transmission.TransmissionID   = car.TransmissionID;
                car.Transmission.TransmissionType = transmissionsRepo.GetTransmissionById(car.TransmissionID).TransmissionType;
                car.ExteriorColor                 = new ExteriorColor();
                car.ExteriorColor.ExteriorColorID = car.ExteriorColorID;
                car.ExteriorColor.Color           = extColorsRepo.GetExteriorColorById(car.ExteriorColorID).Color;
                car.InteriorColor                 = new InteriorColor();
                car.InteriorColor.InteriorColorID = car.InteriorColorID;
                car.InteriorColor.Color           = intColorsRepo.GetInteriorColorById(car.InteriorColorID).Color;
                carsSearched.Add(car);
            }

            return(carsSearched);
        }
Beispiel #6
0
        protected override void Seed(GuildCars.UI.Models.ApplicationDbContext context)
        {
            //AspNetRoles table
            if (!context.Roles.Any(r => r.Name == "Administrator"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Administrator"
                };

                manager.Create(role);
            }

            //AspNetUsers table
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var passwordHasher = new PasswordHasher();
                var store          = new UserStore <ApplicationUser>(context);
                var manager        = new UserManager <ApplicationUser>(store);
                var user           = new ApplicationUser
                {
                    FirstName    = "Bob",
                    LastName     = "Guild",
                    UserName     = "******",
                    Email        = "*****@*****.**",
                    PasswordHash = passwordHasher.HashPassword("Pa$$w0rd1"),
                    RoleID       = 2 // User = 1, Admin = 2
                };

                manager.Create(user);
                manager.AddToRole(user.Id, "Administrator");
            }

            if (context.States.Count() == 0)
            {
                var statesRepo = StateFactory.GetRepository();

                IList <State> statesToAdd = new List <State>();

                foreach (var state in statesRepo.GetStates())
                {
                    statesToAdd.Add(state);
                }

                context.States.AddRange(statesToAdd);

                base.Seed(context);
            }

            if (context.Makes.Count() == 0)
            {
                var makesRepo = MakeFactory.GetRepository();

                IList <Make> makesToAdd = new List <Make>();

                foreach (var make in makesRepo.GetMakes())
                {
                    makesToAdd.Add(make);
                }

                context.Makes.AddRange(makesToAdd);

                base.Seed(context);
            }

            if (context.Models.Count() == 0)
            {
                var modelsRepo = ModelFactory.GetRepository();

                IList <Model> modelsToAdd = new List <Model>();

                foreach (var model in modelsRepo.GetModels())
                {
                    modelsToAdd.Add(model);
                }

                context.Models.AddRange(modelsToAdd);

                base.Seed(context);
            }

            if (context.BodyStyles.Count() == 0)
            {
                var bodyStylesRepo = BodyStyleFactory.GetRepository();

                IList <BodyStyle> bodyStylesToAdd = new List <BodyStyle>();

                foreach (var bodyStyle in bodyStylesRepo.GetBodyStyles())
                {
                    bodyStylesToAdd.Add(bodyStyle);
                }

                context.BodyStyles.AddRange(bodyStylesToAdd);

                base.Seed(context);
            }

            if (context.Conditions.Count() == 0)
            {
                var conditionsRepo = ConditionFactory.GetRepository();

                IList <Condition> conditionsToAdd = new List <Condition>();

                foreach (var condition in conditionsRepo.GetConditions())
                {
                    conditionsToAdd.Add(condition);
                }

                context.Conditions.AddRange(conditionsToAdd);

                base.Seed(context);
            }

            if (context.ExteriorColors.Count() == 0)
            {
                var extColorsRepo = ExteriorColorFactory.GetRepository();

                IList <ExteriorColor> extColorsToAdd = new List <ExteriorColor>();

                foreach (var extColor in extColorsRepo.GetExteriorColors())
                {
                    extColorsToAdd.Add(extColor);
                }

                context.ExteriorColors.AddRange(extColorsToAdd);

                base.Seed(context);
            }

            if (context.ExteriorColors.Count() == 0)
            {
                var extColorsRepo = ExteriorColorFactory.GetRepository();

                IList <ExteriorColor> extColorsToAdd = new List <ExteriorColor>();

                foreach (var extColor in extColorsRepo.GetExteriorColors())
                {
                    extColorsToAdd.Add(extColor);
                }

                context.ExteriorColors.AddRange(extColorsToAdd);

                base.Seed(context);
            }

            if (context.InteriorColors.Count() == 0)
            {
                var intColorsRepo = InteriorColorFactory.GetRepository();

                IList <InteriorColor> intColorsToAdd = new List <InteriorColor>();

                foreach (var intColor in intColorsRepo.GetInteriorColors())
                {
                    intColorsToAdd.Add(intColor);
                }

                context.InteriorColors.AddRange(intColorsToAdd);

                base.Seed(context);
            }

            if (context.PurchaseTypes.Count() == 0)
            {
                var purchaseTypesRepo = PurchaseTypeFactory.GetRepository();

                IList <PurchaseType> purchaseTypesToAdd = new List <PurchaseType>();

                foreach (var purchaseType in purchaseTypesRepo.GetPurchaseTypes())
                {
                    purchaseTypesToAdd.Add(purchaseType);
                }

                context.PurchaseTypes.AddRange(purchaseTypesToAdd);

                base.Seed(context);
            }

            if (context.Specials.Count() == 0)
            {
                var specialsRepo = SpecialsFactory.GetRepository();

                IList <Specials> specialsToAdd = new List <Specials>();

                foreach (var special in specialsRepo.GetSpecials())
                {
                    specialsToAdd.Add(special);
                }

                context.Specials.AddRange(specialsToAdd);

                base.Seed(context);
            }

            if (context.Transmissions.Count() == 0)
            {
                var transmissionsRepo = TransmissionFactory.GetRepository();

                IList <Transmission> transmissionsToAdd = new List <Transmission>();

                foreach (var special in transmissionsRepo.GetTransmissions())
                {
                    transmissionsToAdd.Add(special);
                }

                context.Transmissions.AddRange(transmissionsToAdd);

                base.Seed(context);
            }

            if (context.Cars.Count() == 0)
            {
                var carsRepo = GuildRepositoryFactory.GetRepository();

                IList <Car> carsToAdd = new List <Car>();

                foreach (var car in carsRepo.GetAllCars())
                {
                    carsToAdd.Add(car);
                }

                context.Cars.AddRange(carsToAdd);

                base.Seed(context);
            }

            if (context.GuildRoles.Count() == 0)
            {
                var rolesRepo = RoleFactory.GetRepository();

                IList <GuildRole> rolesToAdd = new List <GuildRole>();

                foreach (var role in rolesRepo.GetRoles())
                {
                    rolesToAdd.Add(role);
                }

                context.GuildRoles.AddRange(rolesToAdd);

                base.Seed(context);
            }
        }
Beispiel #7
0
        public ActionResult Add(CarAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var carRepo           = GuildRepositoryFactory.GetRepository();
                var makesRepo         = MakeFactory.GetRepository();
                var modelRepo         = ModelFactory.GetRepository();
                var typesRepo         = ConditionFactory.GetRepository();
                var bodyStylesRepo    = BodyStyleFactory.GetRepository();
                var transmissionsRepo = TransmissionFactory.GetRepository();
                var extColorsRepo     = ExteriorColorFactory.GetRepository();
                var intColorsRepo     = InteriorColorFactory.GetRepository();

                try
                {
                    model.Car.UserID = AuthorizeUtilities.GetUserId(this);

                    model.Car.BodyStyle                     = new BodyStyle();
                    model.Car.BodyStyle.BodyStyleID         = model.Car.BodyStyleID;
                    model.Car.BodyStyle.BodyStyleName       = bodyStylesRepo.GetBodyStyleById(model.Car.BodyStyleID).BodyStyleName;
                    model.Car.Condition                     = new Condition();
                    model.Car.Condition.ConditionID         = model.Car.ConditionID;
                    model.Car.Condition.ConditionType       = typesRepo.GetConditionById(model.Car.ConditionID).ConditionType;
                    model.Car.ExteriorColor                 = new ExteriorColor();
                    model.Car.ExteriorColor.ExteriorColorID = model.Car.ExteriorColorID;
                    model.Car.ExteriorColor.Color           = extColorsRepo.GetExteriorColorById(model.Car.ExteriorColorID).Color;
                    model.Car.InteriorColor                 = new InteriorColor();
                    model.Car.InteriorColor.InteriorColorID = model.Car.InteriorColorID;
                    model.Car.InteriorColor.Color           = intColorsRepo.GetInteriorColorById(model.Car.InteriorColorID).Color;
                    model.Car.Make                          = new Make();
                    model.Car.Make.MakeID                   = model.Car.MakeID;
                    model.Car.Make.MakeName                 = makesRepo.GetMakeById(model.Car.MakeID).MakeName;
                    model.Car.Make.DateAdded                = DateTime.Now.ToString("MM/dd/yyyy");
                    model.Car.Make.UserID                   = model.Car.UserID;
                    model.Car.Model                         = new Model();
                    model.Car.Model.ModelID                 = model.Car.ModelID;
                    model.Car.Model.MakeID                  = model.Car.MakeID;
                    model.Car.Model.ModelName               = modelRepo.GetModelById(model.Car.ModelID).ModelName;
                    model.Car.Model.DateAdded               = DateTime.Now.ToString("MM/dd/yyyy");
                    model.Car.Model.UserID                  = model.Car.UserID;
                    model.Car.DateAdded                     = DateTime.Now.ToString("MM/dd/yyyy");
                    model.Car.Transmission                  = new Transmission();
                    model.Car.Transmission.TransmissionID   = model.Car.TransmissionID;
                    model.Car.Transmission.TransmissionType = transmissionsRepo.GetTransmissionById(model.Car.TransmissionID).TransmissionType;


                    if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                    {
                        var savepath = Server.MapPath("~/Images");

                        string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                        string extension = Path.GetExtension(model.ImageUpload.FileName);

                        var filePath = Path.Combine(savepath, fileName + extension);

                        /*int counter = 1;
                         * while (System.IO.File.Exists(filePath))
                         * {
                         *  filePath = Path.Combine(savepath, fileName + counter.ToString() + extension);
                         *  counter++;
                         * }*/

                        model.ImageUpload.SaveAs(filePath);
                        model.Car.Photo = Path.GetFileName(filePath);
                    }

                    carRepo.InsertCar(model.Car);
                    bodyStylesRepo.InsertBodyStyle(model.Car.BodyStyle);
                    typesRepo.InsertCondition(model.Car.Condition);
                    extColorsRepo.InsertExteriorColor(model.Car.ExteriorColor);
                    intColorsRepo.InsertInteriorColor(model.Car.InteriorColor);
                    makesRepo.InsertMake(model.Car.Make);
                    modelRepo.InsertModel(model.Car.Model);
                    transmissionsRepo.InsertTransmission(model.Car.Transmission);

                    /*if (Settings.GetRepositoryType() == "EF")
                     * {
                     *  _context.Cars.Add(model.Car);
                     *
                     *  if (model.Car == null)
                     *      model.Car = new Car();
                     *
                     *  _context.SaveChanges();
                     * }
                     * else
                     * {
                     *  carRepo.InsertCar(model.Car);
                     *  bodyStylesRepo.InsertBodyStyle(model.Car.BodyStyle);
                     *  typesRepo.InsertCondition(model.Car.Condition);
                     *  extColorsRepo.InsertExteriorColor(model.Car.ExteriorColor);
                     *  intColorsRepo.InsertInteriorColor(model.Car.InteriorColor);
                     *  makesRepo.InsertMake(model.Car.Make);
                     *  modelRepo.InsertModel(model.Car.Model);
                     *  transmissionsRepo.InsertTransmission(model.Car.Transmission);
                     * }*/

                    return(RedirectToAction("Vehicles"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(View(model));
            }
        }