Example #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,CompanyName,Email,City,State,ZipCode,FaxNumber,Notes,PhoneNumber")] Dealership dealership)
        {
            try
            {
                var    service    = new DealershipAccountService(db);
                string identityId = service.GetCurrentUserIdentity();
                dealership.AutoScoutIdentityUserId = identityId;

                if (ModelState.IsValid)
                {
                    db.Entry(dealership).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    ViewBag.ResponseMessage = "Your changes have been saved.";
                }
                //ViewBag.AutoScoutIdentityUserId = new SelectList(db.Dealerships, "Id", "Email", dealership.AutoScoutIdentityUserId);
                return(View("ManageProfile"));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #2
0
        //GET - retrieve jason representations of vehicle images to render to view
        public JsonResult LoadVehicleImages(int id)
        {
            try
            {
                var vehicleService    = new VehicleSearchService(db);
                var dealershipService = new DealershipAccountService(db);
                var images            = vehicleService.GetAllVehicleImages(id);


                var vehicleImages = new List <VehicleImageViewModel>();
                if (images != null)
                {
                    foreach (var item in images)
                    {
                        var imageBytes = item.ImageBytes;
                        //convert image byte array to base64 string to be rendered properly in browser
                        var imageBytesBase64String = Convert.ToBase64String(imageBytes);


                        vehicleImages.Add(new VehicleImageViewModel(item.Id, imageBytesBase64String));
                    }
                    return(Json(vehicleImages, JsonRequestBehavior.AllowGet));
                }
                return(null);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #3
0
        public ActionResult AddImage(int id, VehicleImage model, HttpPostedFileBase imageFile)
        {
            try
            {
                var db = new AutoScoutDBContext();
                //var vehicle = db.Vehicles.FirstOrDefault(x => x.Id == vehicleId);
                Vehicle vehicle = db.Vehicles.Find(id);

                if (vehicle != null)
                {
                    string make   = vehicle.Make;
                    string vModel = vehicle.Model;
                    string year   = vehicle.Year.ToString();
                    string item   = year + " " + make + " " + vModel;
                    ViewBag.stringDescription = item;
                }

                if (imageFile != null)
                {
                    var service = new ImageManagementService(db);
                    service.AssignImageToVehicle(id, imageFile);
                }

                return(RedirectToAction("Edit", new { id = id }));;
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #4
0
        public async Task <ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                // Generate the token and send it
                var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);

                if (UserManager.SmsService != null)
                {
                    var message = new IdentityMessage
                    {
                        Destination = model.Number,
                        Body        = "Your security code is: " + code
                    };
                    await UserManager.SmsService.SendAsync(message);
                }
                return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number }));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #5
0
        public JsonResult GetCurrentDealershipInfo()
        {
            try
            {
                var service               = new DealershipAccountService(db);
                var currentId             = service.GetCurrentUserDealershipIdFromIdentity();
                var dealership            = db.Dealerships.FirstOrDefault(x => x.Id == currentId);
                var dealershipEditManager = new DealershipManager
                {
                    Id          = dealership.Id,
                    CompanyName = dealership.CompanyName,
                    Email       = dealership.Email,
                    City        = dealership.City,
                    State       = dealership.State,
                    ZipCode     = dealership.ZipCode,
                    Notes       = dealership.Notes,
                    PhoneNumber = dealership.PhoneNumber,
                    FaxNumber   = dealership.FaxNumber
                };

                return(Json(dealershipEditManager, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #6
0
        public JsonResult GetDealershipInfo(int id)
        {
            try
            {
                var service               = new DealershipAccountService(db);
                var dealership            = service.GetDealership(id);
                var dealershipEditManager = new DealershipManager
                {
                    Id          = dealership.Id,
                    CompanyName = dealership.CompanyName,
                    Email       = dealership.Email,
                    City        = dealership.City,
                    State       = dealership.State,
                    ZipCode     = dealership.ZipCode,
                    Notes       = dealership.Notes,
                    PhoneNumber = dealership.PhoneNumber,
                    FaxNumber   = dealership.FaxNumber
                };

                return(Json(dealershipEditManager, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #7
0
        //GET
        public ActionResult AddImage(int?id)
        {
            try
            {
                var vehicle = db.Vehicles.FirstOrDefault(x => x.Id == id);

                if (vehicle != null)
                {
                    string make   = vehicle.Make;
                    string vModel = vehicle.Model;
                    string year   = vehicle.Year.ToString();
                    string item   = year + " " + make + " " + vModel;
                    ViewBag.stringDescription = item;
                }

                VehicleImage image = new VehicleImage();
                return(View(image));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #8
0
        public async Task <ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);

                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    }
                    return(RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess }));
                }
                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("", "Failed to verify phone");
                return(View(model));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #9
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            try
            {
                ViewBag.StatusMessage =
                    message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                    : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                    : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                    : message == ManageMessageId.Error ? "An error has occurred."
                    : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                    : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                    : "";

                var userId = User.Identity.GetUserId();
                var model  = new IndexViewModel
                {
                    HasPassword       = HasPassword(),
                    PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                    TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                    Logins            = await UserManager.GetLoginsAsync(userId),
                    BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
                };
                return(View(model));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #10
0
        public async Task <ActionResult> RemoveLogin(string loginProvider, string providerKey)
        {
            try
            {
                ManageMessageId?message;
                var             result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));

                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    }
                    message = ManageMessageId.RemoveLoginSuccess;
                }
                else
                {
                    message = ManageMessageId.Error;
                }
                return(RedirectToAction("ManageLogins", new { Message = message }));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #11
0
        //
        // GET: /Manage/ManageLogins
        public async Task <ActionResult> ManageLogins(ManageMessageId?message)
        {
            try
            {
                ViewBag.StatusMessage =
                    message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                    : message == ManageMessageId.Error ? "An error has occurred."
                    : "";
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user == null)
                {
                    return(View("Error"));
                }
                var userLogins = await UserManager.GetLoginsAsync(User.Identity.GetUserId());

                var otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList();
                ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
                return(View(new ManageLoginsViewModel
                {
                    CurrentLogins = userLogins,
                    OtherLogins = otherLogins
                }));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #12
0
        //Get - retrieve vehicle search results
        public JsonResult GetSearchResults(string make, string model, string transmission, string style, string condition, int year, int minPrice, int maxPrice, int minMileage, int maxMileage, int cylinderNumber, string exteriorColor)
        {
            try
            {
                using (var db = new AutoScoutDBContext())
                {
                    //create instance of Vehicle Search Service
                    var vehicleSearchService = new VehicleSearchService(db);

                    //send search result criteria from parameters to SearchInventory method which will return matching vehicles
                    var searchResults     = vehicleSearchService.SearchInventory(make, model, year, minPrice, maxPrice, minMileage, maxMileage, transmission, style, condition, cylinderNumber, exteriorColor);
                    var vehicleViewModels = new List <VehicleSearchCriteriaViewModel>();
                    foreach (var item in searchResults)
                    {
                        var companyName = vehicleSearchService.GetCompanyName(item.DealershipId);
                        vehicleViewModels.Add(new VehicleSearchCriteriaViewModel(item.Id, item.Make, item.Model, item.Year, item.Price, item.Mileage, item.Transmission, item.Style, item.Condition, item.CylinderNumber, item.ExteriorColor, item.DealershipId, companyName));
                    }
                    //return JSON objects to view model
                    return(Json(vehicleViewModels, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #13
0
        public async Task <ActionResult> SetPassword(SetPasswordViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);

                    if (result.Succeeded)
                    {
                        var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                        if (user != null)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                        }
                        return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess }));
                    }
                    AddErrors(result);
                }

                // If we got this far, something failed, redisplay form
                return(View(model));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #14
0
        public async Task <ActionResult> RemovePhoneNumber()
        {
            try
            {
                var result = await UserManager.SetPhoneNumberAsync(User.Identity.GetUserId(), null);

                if (!result.Succeeded)
                {
                    return(RedirectToAction("Index", new { Message = ManageMessageId.Error }));
                }
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.RemovePhoneSuccess }));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #15
0
        // GET: Vehicles/Delete/5
        public void Delete(int?id)
        {
            try
            {
                if (id != null)
                {
                    Vehicle vehicle = db.Vehicles.Find(id);
                    if (vehicle != null)
                    {
                        string make  = vehicle.Make;
                        string model = vehicle.Model;
                        string year  = vehicle.Year.ToString();
                        string item  = year + " " + make + " " + model;
                        ViewBag.stringDescription = item;

                        var dealershipService = new DealershipAccountService(db);
                        var currentDealerId   = dealershipService.GetCurrentUserDealershipIdFromIdentity();
                        dealershipService.DeleteVehicleFromInventory(vehicle.Id, currentDealerId);
                    }
                }
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #16
0
        public ActionResult SetProfileImages(HttpPostedFileBase[] headerImageFile)
        {
            try
            {
                //get the dealer id from dealership account service
                var dealershipService = new DealershipAccountService(db);
                var imageService      = new ImageManagementService(db);
                var currentDealerId   = dealershipService.GetCurrentUserDealershipIdFromIdentity();

                //add images to Dealership table using image service
                var dealership = db.Dealerships.FirstOrDefault(x => x.Id == currentDealerId);
                if (dealership != null)
                {
                    //imageService.AssignProfileImagesToDealership(currentDealerId, headerImageFile, iconImageFile);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #17
0
        // GET: Dealerships/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                Dealership dealership = await db.Dealerships.FindAsync(id);

                if (dealership == null)
                {
                    return(HttpNotFound());
                }
                //use the image management service to get the background image converted to a base 64 string
                var imageService = new ImageManagementService(db);

                var iconString       = "";
                var backgroundString = "";

                if (dealership.Icon != null)
                {
                    var dealershipIconImage = imageService.GetDealershipProfileIconAsBase64String(dealership.Id);
                    iconString = "data:image/png;base64," + dealershipIconImage;
                }

                if (dealership.ProfileBackgroundImage != null)
                {
                    var dealershipBackgroundImage = imageService.GetDealershipProfileBackgroundAsBase64String(dealership.Id);
                    backgroundString = "data:image/png;base64," + dealershipBackgroundImage;
                }

                //pass image base 64 strings to view using ViewBag
                ViewBag.Icon       = iconString;
                ViewBag.Background = backgroundString;

                //acquire full vehicle inventory
                var dealershipService = new DealershipAccountService(db);
                var vehicles          = dealershipService.GetAllVehiclesInInventory(dealership.Id);

                ViewBag.Vehicles = vehicles.ToList();

                return(View(dealership));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #18
0
        //
        // GET: /Manage/SetPassword
        public ActionResult SetPassword()
        {
            try
            {
                return(View());
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #19
0
        //
        // GET: /Manage/AddPhoneNumber
        public ActionResult AddPhoneNumber()
        {
            try
            {
                return(View());
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #20
0
        public ActionResult ListItem(Vehicle vehicle)
        {
            try
            {
                return(PartialView(vehicle));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #21
0
        public ActionResult LinkLogin(string provider)
        {
            try
            {
                // Request a redirect to the external login provider to link a login for the current user
                return(new AccountController.ChallengeResult(provider, Url.Action("LinkLoginCallback", "Manage"), User.Identity.GetUserId()));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #22
0
        // GET: Vehicles/Create
        public ActionResult Create()
        {
            try
            {
                ViewBag.DealershipId = new SelectList(db.Dealerships, "Id", "CompanyName");
                return(View());
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #23
0
        public void EditDetails(int id, string companyName, string email, string city, string state, string zipCode, string phoneNumber, string faxNumber, string notes)
        {
            try
            {
                var dealershipService = new DealershipAccountService(db);
                dealershipService.SaveDealershipDetails(id, companyName, email, city, state, zipCode, phoneNumber, faxNumber, notes);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #24
0
        public JsonResult GetModelsFromMake(string make)
        {
            try
            {
                var service = new VehicleSearchService(db);
                var models  = service.GetAllModelsFromMake(make);

                return(Json(models, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #25
0
        public string GetVehicleDealershipName(int dealershipId)
        {
            try
            {
                var vehicleSearchService = new VehicleSearchService(db);
                var dealershipOfVehicle  = vehicleSearchService.GetDealershipData(dealershipId);
                var name = dealershipOfVehicle.CompanyName;
                return(name);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #26
0
        // GET: Dealerships
        public async Task <ActionResult> Index()
        {
            try
            {
                var        dealershipService = new DealershipAccountService(db);
                var        dealershipId      = dealershipService.GetCurrentUserDealershipIdFromIdentity();
                Dealership dealership        = await db.Dealerships.FindAsync(dealershipId);

                return(View(dealership));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #27
0
        //
        // GET: /Manage/VerifyPhoneNumber
        public async Task <ActionResult> VerifyPhoneNumber(string phoneNumber)
        {
            try
            {
                var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), phoneNumber);

                // Send an SMS through the SMS provider to verify the phone number
                return(phoneNumber == null?View("Error") : View(new VerifyPhoneNumberViewModel {
                    PhoneNumber = phoneNumber
                }));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #28
0
        public ActionResult Index()
        {
            try
            {
                var vehicleService = new VehicleSearchService(db);
                var imageService   = new ImageManagementService(db);

                var newestVehicles = vehicleService.GetNewest3Vehicles();
                //var newestVehicleImages = imageService.GetImagesConvertedToBase64Strings();
                return(View(newestVehicles));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #29
0
        // GET: Vehicles/Details/5
        public ActionResult Details(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                Vehicle vehicle = db.Vehicles.Find(id);

                if (vehicle != null)
                {
                    string make  = vehicle.Make;
                    string model = vehicle.Model;
                    string year  = vehicle.Year.ToString();
                    string item  = year + " " + make + " " + model;
                    ViewBag.stringDescription = item;
                }
                if (vehicle == null)
                {
                    return(HttpNotFound());
                }
                var imageBase64Strings = GetVehicleImagesBase64String(vehicle.Id);

                ViewBag.DealershipPhoneNumber = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).PhoneNumber;
                ViewBag.DealershipName        = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).CompanyName;
                ViewBag.ImageBase64Strings    = imageBase64Strings;
                ViewBag.DealershipCity        = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).City;
                ViewBag.DealershipState       = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).State;
                ViewBag.DealershipZipCode     = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).ZipCode;
                ViewBag.DealershipEmail       = db.Dealerships.FirstOrDefault(x => x.Id == vehicle.DealershipId).Email;

                return(View(vehicle));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Example #30
0
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                Vehicle vehicle = db.Vehicles.Find(id);
                ViewBag.VehicleMake  = vehicle.Make;
                ViewBag.VehicleModel = vehicle.Model;
                ViewBag.Year         = vehicle.Year;
                db.Vehicles.Remove(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }