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));
        }
Exemple #2
0
        public IHttpActionResult AddCar([FromBody] CarAddViewModel carViewModel)
        {
            if (ModelState.IsValid)
            {
                Car car = new Car()
                {
                    Model         = carViewModel.Model,
                    Brand         = carViewModel.Brand,
                    MainImage     = carViewModel.MainImage,
                    NumberOfDoors = carViewModel.NumberOfDoors,
                    NumberOfSeats = carViewModel.NumberOfSeats
                };
                if (_carService.AddCar(car))
                {
                    string carObject = JsonConvert.SerializeObject(car, new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    });
                    _carHub.Clients.All.carAdded(carObject);
                    return(Ok());
                }

                return(BadRequest());
            }

            return(BadRequest(ModelState));
        }
Exemple #3
0
        public ActionResult addVehicle()
        {
            ModelMockRepo   modelRepo = new ModelMockRepo();
            MakeMockRepo    makeRepo  = new MakeMockRepo();
            CarAddViewModel vm        = new CarAddViewModel();

            vm.Makes  = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName");
            vm.Models = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName");
            return(View(vm));
        }
Exemple #4
0
        public ActionResult addVehicle(CarAddViewModel vm)
        {
            if (ModelState.IsValid)
            {
                CarMockRepository carRepo = new CarMockRepository();
                vm.Car.ImageFileName = vm.ImageUpload.FileName;
                Car car = carRepo.Create(vm.Car);
                vm.Car.CarId = car.CarId;
                return(RedirectToAction("editVehicle/" + vm.Car.CarId));
            }
            ModelMockRepo modelRepo = new ModelMockRepo();
            MakeMockRepo  makeRepo  = new MakeMockRepo();

            vm.Makes  = new SelectList(makeRepo.GetAllMakes(), "MakeId", "MakeName");
            vm.Models = new SelectList(modelRepo.GetAllModels(), "ModelId", "ModelName");
            return(View(vm));
        }
        public IActionResult Add()
        {
            string user = HttpContext.Session.GetString("userName");

            var model = new CarAddViewModel();

            model.User     = HttpContext.User.Identity.Name.ToString();
            model.TypeList = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "SUV", Value = "SUV"
                },
                new SelectListItem {
                    Text = "SEDAN", Value = "SEDAN"
                },
                new SelectListItem {
                    Text = "HATCHBACK", Value = "HATCHBACK"
                }
            };
            model.GearTypeList = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Manual", Value = "M"
                },
                new SelectListItem {
                    Text = "Automatic", Value = "A"
                },
                new SelectListItem {
                    Text = "Triptonic", Value = "T"
                }
            };
            model.ColorList = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "White", Value = "White"
                },
                new SelectListItem {
                    Text = "Black", Value = "Black"
                },
                new SelectListItem {
                    Text = "Blue", Value = "Blue"
                },
                new SelectListItem {
                    Text = "Red", Value = "Red"
                },
                new SelectListItem {
                    Text = "Grey", Value = "Grey"
                },
                new SelectListItem {
                    Text = "Green", Value = "Green"
                },
                new SelectListItem {
                    Text = "Dark Blue", Value = "Dark Blue"
                },
            };
            model.NumberOfSeatsList = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "2", Value = "2"
                },
                new SelectListItem {
                    Text = "5", Value = "5"
                },
                new SelectListItem {
                    Text = "7", Value = "7"
                },
                new SelectListItem {
                    Text = "10", Value = "10"
                },
            };

            return(View(model));
        }
        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));
            }
        }