Beispiel #1
0
        public ActionResult Specials(SpecialsAddViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                model.Special.UserID = AuthorizeUtilities.GetUserId(this);
            }
            if (ModelState.IsValid)
            {
                var repo = SpecialRepositoryFactory.GetRepository();

                try
                {
                    repo.Insert(model.Special);
                    return(RedirectToAction("Specials"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult Makes(MakesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = MakesRepositoryFactory.GetRepository();

                try
                {
                    Makes make = new CarMastery.Models.Tables.Makes();
                    make.MakeDescription = model.MakeToAdd.MakeDescription;
                    make.UserId          = AuthorizeUtilities.GetUserId(this);
                    make.MakeDateAdded   = DateTime.Now;

                    repo.AddMake(make);

                    return(RedirectToAction("Makes"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(View(model));
            }
        }
Beispiel #3
0
        public ActionResult Makes(string make)
        {
            var repo = new MakeRepoADO();



            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ViewBag.Name = user.Name;

                ViewBag.displayMenu = "No";

                if (IsAdminUser())
                {
                    ViewBag.displayMenu = "Yes";
                }
                if (Request.IsAuthenticated)
                {
                    ViewBag.UserId = AuthorizeUtilities.GetUserId(this);
                }
                var userId = AuthorizeUtilities.GetUserId(this);
                repo.Insert(make, userId);

                var model = repo.GetAll();
                return(View(model));
            }
            else
            {
                ViewBag.Name = "Not Logged IN";

                var model = repo.GetAll();
                return(View(model));
            }
        }
Beispiel #4
0
        public ActionResult Makes(MakesViewModel makes)
        {
            if (ModelState.IsValid)
            {
                var makesRepo = MakeFactory.GetRepository();

                makes.Make.UserID    = AuthorizeUtilities.GetUserId(this);
                makes.Make.DateAdded = DateTime.Now.ToString("MM/dd/yyyy");
                makesRepo.InsertMake(makes.Make);

                var allUsers = _context.Users.ToList();
                var allMakes = _context.Makes.ToList();

                makes.Makes   = makesRepo.GetMakes();
                makes.MakesVM = new List <MakesViewModel>();

                makes.MakesVM = allMakes.Select(x => new MakesViewModel
                {
                    MakeName  = x.MakeName,
                    DateAdded = x.DateAdded,
                    User      = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault()
                }).ToList();

                return(View(makes));
            }
            else
            {
                return(View(makes));
            }
        }
        public ActionResult Models(ModelsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = ModelsRepositoryFactory.GetRepository();

                try
                {
                    CarMastery.Models.Tables.Models addModel = new CarMastery.Models.Tables.Models();
                    addModel.UserId           = AuthorizeUtilities.GetUserId(this);
                    addModel.ModelDateAdded   = DateTime.Now;
                    addModel.ModelDescription = model.ModelToAdd.ModelDescription;
                    addModel.MakeId           = model.ModelToAdd.MakeId;

                    repo.AddModel(addModel);

                    return(RedirectToAction("Models"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var makesRepo = MakesRepositoryFactory.GetRepository();
                model.Makes = new SelectList(makesRepo.GetAllMakes(), "MakeId", "MakeDescription");
                return(View(model));
            }
        }
Beispiel #6
0
        public ActionResult Contacts()
        {
            var userId = AuthorizeUtilities.GetUserId(this);

            var repo  = AccountRepositoryFactory.GetRepository();
            var model = repo.GetContacts(userId);

            return(View(model));
        }
Beispiel #7
0
        public ActionResult Purchase(PurchaseViewModel model)
        {
            var stateId    = model.Transaction.StateID;
            var purchaseId = model.Transaction.PurchaseTypeID;

            if (ModelState.IsValid)
            {
                var purchaseTypeRepo = PurchaseTypeFactory.GetRepository();
                var transactionRepo  = TransactionFactory.GetRepository();
                var statesRepo       = StateFactory.GetRepository();

                try
                {
                    model.Transaction.State                         = new State();
                    model.Transaction.State.StateID                 = stateId;
                    model.Transaction.State.StateName               = statesRepo.GetStateById(model.Transaction.StateID).StateName;
                    model.Transaction.PurchaseType                  = new PurchaseType();
                    model.Transaction.PurchaseType.PurchaseTypeID   = purchaseId;
                    model.Transaction.PurchaseType.PurchaseTypeName = purchaseTypeRepo.GetPurchaseTypeById(model.Transaction.PurchaseTypeID).PurchaseTypeName;
                    model.Transaction                = new Transaction();
                    model.Transaction.UserID         = AuthorizeUtilities.GetUserId(this);
                    model.Transaction.StateID        = stateId;
                    model.Transaction.PurchaseTypeID = purchaseId;
                    model.Transaction.AddressStreet1 = model.AddressStreet1;
                    model.Transaction.AddressStreet2 = model.AddressStreet2;
                    model.Transaction.CarID          = model.CarID;
                    model.Transaction.City           = model.City;
                    model.Transaction.Email          = model.Email;
                    model.Transaction.FirstName      = model.FirstName;
                    model.Transaction.LastName       = model.LastName;
                    model.Transaction.PurchasePrice  = model.PurchasePrice;
                    model.Transaction.PurchaseDate   = DateTime.Now.ToString("MM/dd/yyyy");
                    model.Transaction.Role           = model.Role;
                    model.Transaction.ZipCode        = model.ZipCode;

                    transactionRepo.InsertTransaction(model.Transaction);

                    /*_context.Transactions.Add(model.Transaction);
                     *
                     * if (model.Transaction == null)
                     *  model.Transaction = new Transaction();
                     *
                     * _context.SaveChanges();*/

                    return(RedirectToAction(""));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(View(model));
            }
        }
Beispiel #8
0
        public ActionResult DeleteFavorite(int ListingId)
        {
            var userId = AuthorizeUtilities.GetUserId(this);

            var repo = AccountRepositoryFactory.GetRepository();

            repo.RemoveFavorite(userId, ListingId);

            return(RedirectToAction("Favorites"));
        }
Beispiel #9
0
        public ActionResult Makes()
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserID = AuthorizeUtilities.GetUserId(this);
            }
            var repo  = MakeRepositoryFactory.GetRepository();
            var model = repo.GetMakeList();

            return(View(model));
        }
        public ActionResult Details(int id)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserId = AuthorizeUtilities.GetUserId(this);
            }
            var repo  = new MobileSuitRepositoryADO();
            var model = repo.GetDetails(id);


            return(View(model));
        }
        public ActionResult Details(int id)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserId = AuthorizeUtilities.GetUserId(this);
            }

            var repo  = VehicleRepositoryFactory.GetRepository();
            var model = repo.GetDetailById(id);

            return(View(model));
        }
Beispiel #12
0
        public ActionResult Sales()
        {
            SearchSalesVM model    = new SearchSalesVM();
            var           userList = AuthorizeUtilities.GetUsersInRole("sales");

            model.Users = from u in userList
                          select new SelectListItem {
                Text = u.FirstName + ' ' + u.LastName, Value = u.Id.ToString()
            };

            return(View(model));
        }
Beispiel #13
0
        public ActionResult Specials()
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserID = AuthorizeUtilities.GetUserId(this);
            }
            var repo  = SpecialRepositoryFactory.GetRepository();
            var model = new SpecialsAddViewModel();

            model.SpecialList = repo.GetAll();

            return(View(model));
        }
Beispiel #14
0
        public ActionResult Add(ListingAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = ListingRepositoryFactory.GetRepository();

                try
                {
                    model.Listing.UserId = AuthorizeUtilities.GetUserId(this);

                    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.Listing.ImageFileName = Path.GetFileName(filePath);
                    }

                    repo.Insert(model.Listing);

                    return(RedirectToAction("Edit", new { id = model.Listing.ListingId }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var statesRepo   = StatesRepositoryFactory.GetRepository();
                var bathroomRepo = BathroomTypesRepositoryFactory.GetRepository();

                model.States        = new SelectList(statesRepo.GetAll(), "StateId", "StateId");
                model.BathroomTypes = new SelectList(bathroomRepo.GetAll(), "BathroomTypeId", "BathroomTypeName");

                return(View(model));
            }
        }
Beispiel #15
0
        public ActionResult Models()
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserID = AuthorizeUtilities.GetUserId(this);
            }
            var repo     = ModelRepositoryFactory.GetRepository();
            var makeRepo = MakeRepositoryFactory.GetRepository();
            var model    = new ModelsListViewModel();

            model.ModelList = repo.GetModelList();
            model.SetMakeItems(makeRepo.GetAll());
            return(View(model));
        }
Beispiel #16
0
        public ActionResult Purchase(PurchaseVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo         = VehicleRepositoryFactory.GetRepository();
                var customerRepo = CustomersRepositoryFactory.GetRepository();
                var salesRepo    = SalesRepositoryFactory.GetRepository();
                var vehiclesRepo = VehicleRepositoryFactory.GetRepository();

                Vehicles vehicleToEdit = new Vehicles();

                try
                {
                    customerRepo.AddCustomer(model.Customer);

                    Sales addSale = new Sales();
                    addSale.CustomerId  = model.Customer.CustomerId;
                    addSale.VehicleId   = model.Vehicle.VehicleId;
                    addSale.FinancingId = model.Sale.FinancingId;
                    addSale.UserId      = AuthorizeUtilities.GetUserId(this);
                    addSale.SaleAmount  = model.Sale.SaleAmount;
                    addSale.SaleDate    = DateTime.Now;

                    salesRepo.AddSale(addSale);

                    vehicleToEdit = vehiclesRepo.SelectVehicle(model.Vehicle.VehicleId);
                    vehicleToEdit.VehicleIsFeatured = false;
                    vehiclesRepo.UpdateVehicle(vehicleToEdit);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var inventoryRepo = InventoryRepositoryFactory.GetRepository();
                var statesRepo    = StatesRepositoryFactory.GetRepository();
                var financingRepo = FinancingRepositoryFactory.GetRepository();

                model.Vehicle   = inventoryRepo.GetVehicleDetails(model.Vehicle.VehicleId);
                model.States    = new SelectList(statesRepo.GetAllStates(), "StateId", "StateId");
                model.Financing = new SelectList(financingRepo.GetAllFinancing(), "FinancingId", "FinancingDescription");

                return(View(model));
            }
        }
Beispiel #17
0
        public ActionResult Purchase(int id)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.UserID = AuthorizeUtilities.GetUserId(this);
            }

            var repo      = VehicleRepositoryFactory.GetRepository();
            var staterepo = StateRepositoryFactory.GetRepository();
            var model     = new PurchaseAddViewModel();

            model.VehicleDetails     = repo.GetDetails(id);
            model.Purchase.VehicleID = id;
            model.SetStateItems(staterepo.GetAll());
            return(View(model));
        }
Beispiel #18
0
        public ActionResult Edit(int id)
        {
            var model = new ListingEditViewModel();

            var statesRepo   = StatesRepositoryFactory.GetRepository();
            var bathroomRepo = BathroomTypesRepositoryFactory.GetRepository();
            var listingsRepo = ListingRepositoryFactory.GetRepository();

            model.States        = new SelectList(statesRepo.GetAll(), "StateId", "StateId");
            model.BathroomTypes = new SelectList(bathroomRepo.GetAll(), "BathroomTypeId", "BathroomTypeName");
            model.Listing       = listingsRepo.GetById(id);

            if (model.Listing.UserId != AuthorizeUtilities.GetUserId(this))
            {
                throw new Exception("Attempt to edit a listing you do not own! Naughty!");
            }

            return(View(model));
        }
Beispiel #19
0
        public ActionResult DeleteVehicle(int vehicleID)
        {
            var userId = AuthorizeUtilities.GetUserId(this);

            var repo            = VehicleRepositoryFactory.GetRepository();
            var vehicleToDelete = repo.GetbyId(vehicleID);

            var savepath = Server.MapPath("~/Images");
            var oldPath  = Path.Combine(savepath, vehicleToDelete.ImageFileName);

            if (System.IO.File.Exists(oldPath))
            {
                System.IO.File.Delete(oldPath);
            }

            repo.Delete(vehicleID);

            return(RedirectToAction("Vehicles"));
        }
Beispiel #20
0
        public ActionResult Models(ModelsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var modelsRepo = ModelFactory.GetRepository();
                var makesRepo  = MakeFactory.GetRepository();

                model.Model           = new Model();
                model.Model.MakeID    = model.Car.MakeID;
                model.Model.ModelName = model.Car.Model.ModelName;
                model.Model.UserID    = AuthorizeUtilities.GetUserId(this);
                model.Model.DateAdded = DateTime.Now.ToString("MM/dd/yyyy");

                modelsRepo.InsertModel(model.Model);

                var allUsers  = _context.Users.ToList();
                var allMakes  = _context.Makes.ToList();
                var allModels = _context.Models.ToList();

                List <ModelsViewModel> modelList = allModels.Select(x => new ModelsViewModel
                {
                    MakeName  = allMakes.Where(y => y.MakeID == x.MakeID).Select(y => y.MakeName).FirstOrDefault(),
                    ModelName = x.ModelName,
                    DateAdded = x.DateAdded,
                    User      = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault()
                }).ToList();


                ModelsViewModel viewModel = new ModelsViewModel
                {
                    Makes    = makesRepo.GetMakes(),
                    Models   = modelsRepo.GetModels(),
                    ModelsVM = modelList
                };

                return(View(viewModel));
            }
            else
            {
                return(View(model));
            }
        }
Beispiel #21
0
        public ActionResult Details(SalesViewModel temp)
        {
            var repo = new PurchaseRepoADO();


            var suit = temp.MobileSuit;
            var sale = temp.Sale;

            sale.InventoryNumber = suit.InventoryNumber;
            sale.SerialNumber    = suit.SerialNumber;
            sale.Type            = suit.Type;
            sale.Price           = suit.SalePrice;
            var user = AuthorizeUtilities.GetUserId(this);

            repo.Insert(sale, user);
            //model.MobileSuit = modelfirst;
            //if (User.Identity.IsAuthenticated)
            //{
            //    var user = User.Identity;
            //    ViewBag.Name = user.Name;

            //    ViewBag.displayMenu = "No";

            //    if (IsAdminUser())
            //    {
            //        ViewBag.displayMenu = "Yes";
            //    }
            //    if (Request.IsAuthenticated)
            //    {
            //        ViewBag.UserId = AuthorizeUtilities.GetUserId(this);
            //    }
            //    return View(model);
            //}
            //else
            //{
            //    ViewBag.Name = "Not Logged IN";
            //    return View(model);
            //}
            return(View(temp));
        }
Beispiel #22
0
        public ActionResult Purchase(PurchaseAddViewModel model)
        {
            if (Request.IsAuthenticated)
            {
                model.Purchase.UserID = AuthorizeUtilities.GetUserId(this);
            }

            if (ModelState.IsValid)
            {
                var customerRepo = CustomerRepositoryFactory.GetRepository();
                var purchaseRepo = PurchaseRepositoryFactory.GetRepository();
                try
                {
                    customerRepo.Insert(model.Customer);

                    model.Purchase.CustomerID = model.Customer.CustomerID;
                    model.Purchase.VehicleID  = model.VehicleDetails.VehicleID;

                    purchaseRepo.Insert(model.Purchase);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var repo      = VehicleRepositoryFactory.GetRepository();
                var staterepo = StateRepositoryFactory.GetRepository();

                model.VehicleDetails     = repo.GetDetails(model.VehicleDetails.VehicleID);
                model.Purchase.VehicleID = model.VehicleDetails.VehicleID;
                model.SetStateItems(staterepo.GetAll());

                return(View(model));
            }
        }
Beispiel #23
0
        public ActionResult Details(int id)
        {
            var repo       = new MobileSuitRepositoryADO();
            var modelfirst = repo.GetDetails(id);
            var model      = new SalesViewModel();
            var statesrepo = new StateRepositoryADO();

            model.States = new SelectList(statesrepo.GetAll(), "StateId", "Name");
            var purchaseRepo = new PurchaseRepoADO();

            model.Purchase = new SelectList(purchaseRepo.GetAll(), "TypeId", "Type");


            model.MobileSuit = modelfirst;
            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ViewBag.Name = user.Name;

                ViewBag.displayMenu = "No";

                if (IsAdminUser())
                {
                    ViewBag.displayMenu = "Yes";
                }
                if (Request.IsAuthenticated)
                {
                    ViewBag.UserId = AuthorizeUtilities.GetUserId(this);
                }
                return(View(model));
            }
            else
            {
                ViewBag.Name = "Not Logged IN";
                return(View(model));
            }
        }
Beispiel #24
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));
            }
        }