public ActionResult Vehicles() { var repo = CarMasterRepoFactory.Create(); var model = repo.GetVehiclesForSale(); return(View(model)); }
public ActionResult AddUser(UserViewModel model) { var repo = CarMasterRepoFactory.Create(); if (model.Password != model.ConfirmPassword) { ModelState.AddModelError("ConfirmPassword", "Error: Passwords do not match"); } else if (string.IsNullOrEmpty(model.User.FirstName)) { ModelState.AddModelError("FirstName", "Please enter a firstname"); } if (ModelState.IsValid) { User userToCreate = new User(); userToCreate.FirstName = model.User.FirstName; userToCreate.LastName = model.User.LastName; userToCreate.Email = model.User.Email; userToCreate.Password = model.User.Password; userToCreate.ConfirmPassword = model.User.ConfirmPassword; userToCreate.Role = model.User.Role; repo.AddUser(userToCreate); return(RedirectToAction("Users")); } else { var newModel = new UserViewModel(); newModel.SetRoles(CarMasterRepoFactory.Create().GetAllRoles()); return(View(newModel)); } }
public ActionResult Users() { var repo = CarMasterRepoFactory.Create(); var model = repo.GetAllUsers(); return(View(model)); }
public ActionResult Makes(Make makeToAdd) { var repo = CarMasterRepoFactory.Create(); repo.CreateMake(makeToAdd); return(RedirectToAction("Makes")); }
public ActionResult Details(int id) { var repo = CarMasterRepoFactory.Create(); var model = repo.GetSingleVehicle(id); return(View(model)); }
public ActionResult Index() { var repo = CarMasterRepoFactory.Create(); var model = repo.GetFeaturedVehicles(); return(View(model)); }
public ActionResult SalesReport() { var repo = CarMasterRepoFactory.Create(); var users = repo.GetAllUsers(); return(View(users)); }
public ActionResult AddUser() { var repo = CarMasterRepoFactory.Create(); var model = new UserViewModel(); model.SetRoles(repo.GetAllRoles()); return(View(model)); }
public ActionResult Models() { var repo = CarMasterRepoFactory.Create(); AddModelViewModel model = new AddModelViewModel(); model.SetMakesList(repo.GetAllMakes()); return(View(model)); }
//SPECIALS public ActionResult Specials() { var repo = CarMasterRepoFactory.Create(); AminSpecialVM model = new AminSpecialVM(); model.SpecialsList = repo.GetAllSpecials(); return(View(model)); }
public ActionResult EditUser(int id) { var repo = CarMasterRepoFactory.Create(); var model = new UserViewModel(); model.User = repo.GetUserById(id); model.SetRoles(CarMasterRepoFactory.Create().GetAllRoles()); return(View(model)); }
public ActionResult Purchase(int id) { var repo = CarMasterRepoFactory.Create(); var model = new PurchaseViewModel(); model.Vehicle = repo.GetSingleVehicle(id); model.SetPurchaseTypes(repo.GetAllPurchaseTypes()); model.SetStates(repo.GetAllStates()); return(View(model)); }
public IHttpActionResult GetMakes() { var repo = CarMasterRepoFactory.Create(); try { var result = repo.GetAllMakes(); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult AddVehicle() { var repo = CarMasterRepoFactory.Create(); var model = new VehicleAdminViewModel(); model.SetMakes(repo.GetAllMakes()); model.SetModels(repo.GetAllModels()); model.SetTypes(repo.GetAllVehicleTypes()); model.SetBodyStyles(repo.GetAllBodyStyles()); model.SetTransmissions(repo.GetAllTransmissions()); model.SetInteriorColors(repo.GetAllInteriorColors()); model.SetExteriorColors(repo.GetAllExteriorColors()); return(View(model)); }
public ActionResult DeleteVehicle(int id) { var repo = CarMasterRepoFactory.Create(); if (ModelState.IsValid) { repo.DeleteVehicle(id); return(RedirectToAction("Vehicles")); } else { return(RedirectToAction("Vehicles")); } }
public ActionResult DeleteSpecial(int id) { var repo = CarMasterRepoFactory.Create(); if (ModelState.IsValid) { repo.DeleteSpecial(id); return(RedirectToAction("Specials")); } else { //AminSpecialVM newModel = new AminSpecialVM(); //newModel.SpecialsList = repo.GetAllSpecials(); return(RedirectToAction("Specials")); } }
public ActionResult Contact(Contact contact) { var repo = CarMasterRepoFactory.Create(); if (string.IsNullOrWhiteSpace(contact.Email) || string.IsNullOrWhiteSpace(contact.Phone)) { ModelState.AddModelError("", "Either phone number or email must be provided."); } if (ModelState.IsValid) { repo.CreateContact(contact); return(RedirectToAction("Index")); } else { return(View()); } }
public ActionResult EditUser(User user) { var repo = CarMasterRepoFactory.Create(); if (user.Password != user.ConfirmPassword) { ModelState.AddModelError("ConfirmPassword", "Error: Passwords do not match"); } if (ModelState.IsValid) { repo.EditUser(user); return(RedirectToAction("Users")); } else { var model = new UserViewModel(); model.User = repo.GetUserById(user.UserId); model.SetRoles(CarMasterRepoFactory.Create().GetAllRoles()); return(View(model)); } }
public ActionResult CreateSpecial(AminSpecialVM model) { var repo = CarMasterRepoFactory.Create(); if (ModelState.IsValid) { Special special = new Special(); special.SpecialTitle = model.Special.SpecialTitle; special.SpecialDescription = model.Special.SpecialDescription; repo.CreateSpecial(special); return(RedirectToAction("Specials")); } else { AminSpecialVM newModel = new AminSpecialVM(); newModel.SpecialsList = repo.GetAllSpecials(); return(View(newModel)); } }
public ActionResult Inventory() { var repo = CarMasterRepoFactory.Create(); var vehicles = repo.GetVehiclesForSale(); var newVehicleList = vehicles.Where(x => x.VehicleType.TypeDescription.Equals("New")); var usedVehicleList = vehicles.Where(x => x.VehicleType.TypeDescription.Equals("Used")); //Set inventoryVM lists to new list of detailVM InventoryViewModel viewModel = new InventoryViewModel(); viewModel.NewVehicles = new List <InventoryDetailsViewModel>(); viewModel.UsedVehicles = new List <InventoryDetailsViewModel>(); //List of new vehicles foreach (var vehicle in newVehicleList) { InventoryDetailsViewModel view = new InventoryDetailsViewModel(); view.Year = vehicle.Year; view.Make = vehicle.Model.Make.MakeDescription; view.Model = vehicle.Model.ModelDescription; view.Count = newVehicleList.Count(); view.StockValue = newVehicleList.Select(x => x.MSRP).Sum(); viewModel.NewVehicles.Add(view); } //List of used vehicles foreach (var vehicle in usedVehicleList) { InventoryDetailsViewModel view = new InventoryDetailsViewModel(); view.Year = vehicle.Year; view.Make = vehicle.Model.Make.MakeDescription; view.Model = vehicle.Model.ModelDescription; view.Count = usedVehicleList.Count(); view.StockValue = usedVehicleList.Select(x => x.MSRP).Sum(); viewModel.UsedVehicles.Add(view); } //Send list of new and used to view return(View(viewModel)); }
public IHttpActionResult SearchSalesVehicles(string input, decimal?minPrice, decimal?maxPrice, int?minYear, int?maxYear) { var repo = CarMasterRepoFactory.Create(); try { var parameters = new SearchViewModel() { Input = input, MinPrice = minPrice, MaxPrice = maxPrice, MinYear = minYear, MaxYear = maxYear }; var result = repo.SearchSalesVehicles(parameters); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult AddModel(AddModelViewModel modelToCreate) { //VM-Model and makeslist //Model //ModelId, ModelDescription, DateAdded, MakeId var repo = CarMasterRepoFactory.Create(); if (ModelState.IsValid) { //Model newModel = new Model(); //modelToCreate.Model.DateAdded = DateTime.Now; //m.Model.DateAdded = DateTime.Now; //newModel.ModelDescription = m.Model.ModelDescription; //newModel.Make.MakeId = m.Model.Make.MakeId; repo.CreateModel(modelToCreate.Model); return(RedirectToAction("Models")); } else { AddModelViewModel result = new AddModelViewModel(); result.SetMakesList(repo.GetAllMakes()); return(View(result)); } }
public IHttpActionResult GetSalesReport(int?userId, string fromDate, string toDate) { var repo = CarMasterRepoFactory.Create(); try { DateTime fDate = DateTime.Parse(fromDate); DateTime tDate = DateTime.Parse(toDate); var parameters = new TotalSalesViewModel() { UserId = userId, FromDate = fDate, ToDate = tDate }; var result = repo.SearchPurchases(parameters); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Purchase(PurchaseViewModel model) { var repo = CarMasterRepoFactory.Create(); var vehicle = repo.GetSingleVehicle(model.Vehicle.VehicleId); var user = repo.GetUserById(1); if (string.IsNullOrWhiteSpace(model.Purchase.Name)) { ModelState.AddModelError("Purchase.Name", "Name is required."); } if (string.IsNullOrWhiteSpace(model.Purchase.Phone) && string.IsNullOrWhiteSpace(model.Purchase.Email)) { ModelState.AddModelError("Purchase.Phone", "Phone or email required."); } if (string.IsNullOrWhiteSpace(model.Purchase.StreetAddress1)) { ModelState.AddModelError("Purchase.StreetAddress1", "Street Address 1 is required."); } if (string.IsNullOrWhiteSpace(model.Purchase.City)) { ModelState.AddModelError("Purchase.City", "City is required."); } if (model.Purchase.ZipCode.ToString().Length < 5 || model.Purchase.ZipCode.ToString().Length > 5) { ModelState.AddModelError("Purchase.ZipCode", "Zipcode must be 5 digits long."); } if (model.Purchase.PurchasePrice < vehicle.SalePrice * 95 / 100) { ModelState.AddModelError("Purchase.PurchasePrice", "Purchase price cannot be less than 95% of the sales price."); } if (model.Purchase.PurchasePrice > vehicle.MSRP) { ModelState.AddModelError("Purchase.PurchasePrice", "Purchase price may not exceed MSRP"); } if (ModelState.IsValid) { Purchase purchase = new Purchase(); purchase.Name = model.Purchase.Name; purchase.Phone = model.Purchase.Phone; purchase.Email = model.Purchase.Email; purchase.StreetAddress1 = model.Purchase.StreetAddress1; purchase.StreetAddress2 = model.Purchase.StreetAddress2; purchase.City = model.Purchase.City; purchase.ZipCode = model.Purchase.ZipCode; purchase.PurchasePrice = model.Purchase.PurchasePrice; purchase.DatePurchased = DateTime.Now; purchase.PurchaseTypeId = model.Purchase.PurchaseTypeId; purchase.StateId = model.Purchase.StateId; purchase.Vehicle = vehicle; purchase.VehicleId = model.Vehicle.VehicleId; purchase.UserId = user.UserId; purchase.Vehicle.SoldOut = true; purchase.Vehicle.Featured = false; //model.Purchase.Vehicle.SoldOut = true; //model.Purchase.Vehicle.Featured = false; vehicle.SoldOut = true; vehicle.Featured = false; repo.UpdateVehicle(model.Vehicle); repo.AddPurchase(purchase); return(RedirectToAction("Index")); } else { //var repo = CarMasterRepoFactory.Create(); var newModel = new PurchaseViewModel(); newModel.Vehicle = repo.GetSingleVehicle(model.Vehicle.VehicleId); newModel.SetPurchaseTypes(repo.GetAllPurchaseTypes()); newModel.SetStates(repo.GetAllStates()); return(View(newModel)); } }
public ActionResult EditVehicle(VehicleAdminViewModel m) { //var repo = CarMasterRepoFactory.Create(); //int nextYear = DateTime.Now.Year + 1; //if (model.Vehicle.Year < 2000 || model.Vehicle.Year > nextYear) //{ // ModelState.AddModelError("Vehicle.Year", "The vehicle year must be between the year 2000 and this year plus 1."); //} //if (model.Vehicle.VehicleType.VehicleTypeId.Equals(1) && model.Vehicle.Mileage > 1000 || model.Vehicle.Mileage < 0) //{ // ModelState.AddModelError("Vehicle.VehicleType.VehicleTypeId", "New vehicle mileage must be between 0 and 1000."); //} //if (model.Vehicle.VehicleType.VehicleTypeId.Equals(2) && model.Vehicle.Mileage < 1000) //{ // ModelState.AddModelError("Vehicle.VehicleType.VehicleTypeId", "Used vehicle mileage must be greater than 1000."); //} //if (string.IsNullOrWhiteSpace(model.Vehicle.Vin)) //{ // ModelState.AddModelError("Vehicle.Vin", "VIN# is required."); //} //if (model.Vehicle.MSRP < 1) //{ // ModelState.AddModelError("Vehicle.MSRP", "MSRP must be a positive number."); //} //if (model.Vehicle.SalePrice < 1) //{ // ModelState.AddModelError("Vehicle.SalePrice", "Sale Price must be a positive number."); //} //if (model.Vehicle.SalePrice > model.Vehicle.MSRP) //{ // ModelState.AddModelError("", "Sale Price must not exceed MSRP."); //} //if (string.IsNullOrWhiteSpace(model.Vehicle.VehicleDescription)) //{ // ModelState.AddModelError("Vehicle.VehicleDescription", "Description is required."); //} //if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) //{ // var ext = new string[] { ".png", ".jpg", ".jpeg", ".gif" }; // if (!ext.Contains(extension)) // { // ModelState.AddModelError("ImageUpload", "Image file must be a .png, .jpeg, .jpg, of .gif."); // } //} //else //{ // ModelState.AddModelError("ImageUpload", "Image is required."); //} if (ModelState.IsValid) { var repo = CarMasterRepoFactory.Create(); try { var old = repo.GetSingleVehicle(m.Vehicle.VehicleId); if (m.ImageUpload != null && m.ImageUpload.ContentLength > 0) { var savePath = Server.MapPath("~/Images"); string extension = Path.GetExtension(m.ImageUpload.FileName); string fileName = Path.GetFileNameWithoutExtension(m.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++; } m.ImageUpload.SaveAs(filePath); m.Vehicle.ImageFileName = Path.GetFileName(filePath); //Delete old file var oldPath = Path.Combine(savePath, old.ImageFileName); if (System.IO.File.Exists(oldPath)) { System.IO.File.Delete(oldPath); } } else { //if replace image, delete old one and replace m.Vehicle.ImageFileName = old.ImageFileName; } m.Vehicle.ModelId = m.Vehicle.Model.ModelId; m.Vehicle.VehicleDescription = m.Vehicle.VehicleType.TypeDescription; repo.UpdateVehicle(m.Vehicle); return(RedirectToAction("EditVehicle", new { id = m.Vehicle.VehicleId })); } catch (Exception ex) { throw ex; } } else { var repo = CarMasterRepoFactory.Create(); var newModel = new VehicleAdminViewModel(); newModel.SetMakes(repo.GetAllMakes()); newModel.SetModels(repo.GetAllModels()); newModel.SetBodyStyles(repo.GetAllBodyStyles()); newModel.SetTransmissions(repo.GetAllTransmissions()); newModel.SetInteriorColors(repo.GetAllInteriorColors()); newModel.SetExteriorColors(repo.GetAllExteriorColors()); return(View(newModel)); } }
public IHttpActionResult GetModelByMake(int id) { List <Model> models = CarMasterRepoFactory.Create().GetModelByMakeId(id); return(Ok(models)); }
public ActionResult AddVehicle(VehicleAdminViewModel model) { var repo = CarMasterRepoFactory.Create(); int nextYear = DateTime.Now.Year + 1; if (model.Vehicle.Year < 2000 || model.Vehicle.Year > nextYear) { ModelState.AddModelError("Vehicle.Year", "The vehicle year must be between the year 2000 and this year plus 1."); } if (model.Vehicle.VehicleType.VehicleTypeId.Equals(1) && model.Vehicle.Mileage > 1000 || model.Vehicle.Mileage < 0) { ModelState.AddModelError("Vehicle.VehicleType.VehicleTypeId", "New vehicle mileage must be between 0 and 1000."); } if (model.Vehicle.VehicleType.VehicleTypeId.Equals(2) && model.Vehicle.Mileage < 1000) { ModelState.AddModelError("Vehicle.VehicleType.VehicleTypeId", "Used vehicle mileage must be greater than 1000."); } if (string.IsNullOrWhiteSpace(model.Vehicle.Vin)) { ModelState.AddModelError("Vehicle.Vin", "VIN# is required."); } if (model.Vehicle.MSRP < 1) { ModelState.AddModelError("Vehicle.MSRP", "MSRP must be a positive number."); } if (model.Vehicle.SalePrice < 1) { ModelState.AddModelError("Vehicle.SalePrice", "Sale Price must be a positive number."); } if (model.Vehicle.SalePrice > model.Vehicle.MSRP) { ModelState.AddModelError("", "Sale Price must not exceed MSRP."); } if (string.IsNullOrWhiteSpace(model.Vehicle.VehicleDescription)) { ModelState.AddModelError("Vehicle.VehicleDescription", "Description is required."); } if (ModelState.IsValid) { try { //Vehicle vehicle = new Vehicle(); //vehicle.ModelId = model.Vehicle.ModelId; //vehicle.VehicleTypeId = model.Vehicle.VehicleTypeId; //vehicle.BodyStyleId = model.Vehicle.BodyStyleId; //vehicle.Year = model.Vehicle.Year; //vehicle.TransmissionId = model.Vehicle.TransmissionId; //vehicle.ExteriorColorId = model.Vehicle.ExteriorColorId; //vehicle.InteriorColorId = model.Vehicle.InteriorColorId; //vehicle.MSRP = model.Vehicle.MSRP; //vehicle.SalePrice = model.Vehicle.SalePrice; //vehicle.SoldOut = false; //vehicle.Featured = false; //vehicle.VehicleDescription = model.Vehicle.VehicleDescription; //vehicle.Vin = model.Vehicle.Vin; //model.Vehicle.DateModified = null; string extension = Path.GetExtension(model.ImageUpload.FileName); if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savePath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(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.Vehicle.ImageFileName = Path.GetFileName(filePath); } } catch { Console.WriteLine("Error"); } repo.CreateVehicle(model.Vehicle); return(RedirectToAction("EditVehicle", "Admin", new { id = model.Vehicle.VehicleId })); } else { var newModel = new VehicleAdminViewModel(); newModel.SetMakes(repo.GetAllMakes()); newModel.SetModels(repo.GetAllModels()); newModel.SetBodyStyles(repo.GetAllBodyStyles()); newModel.SetTransmissions(repo.GetAllTransmissions()); newModel.SetInteriorColors(repo.GetAllInteriorColors()); newModel.SetExteriorColors(repo.GetAllExteriorColors()); return(View(newModel)); } }