Ejemplo n.º 1
0
        public void AssignImageToVehicle(int vehicleId, HttpPostedFileBase imageFile)
        {
            try
            {
                if (imageFile != null)
                {
                    //create a byte array of appopriate length
                    var imageBytes = new byte[imageFile.ContentLength];

                    //convert image file to byte array and assign to imageBytes
                    imageFile.InputStream.Read(imageBytes, 0, imageFile.ContentLength);

                    //create new vehicle image, assign VehicleId to Id of Vehicle of which the image belongs
                    var vehicleImage = new VehicleImage
                    {
                        VehicleId  = vehicleId,
                        ImageBytes = imageBytes,
                    };

                    //add new vehicle image to database table - VehicleImages, ans save
                    db.VehicleImages.Add(vehicleImage);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 2
0
        //Acquire string of base 64 strings, to pull vehicle images from the db to the view to be rendered in the browser
        public string GetPreviewImageConvertedToBase64String(int vehicleId)
        {
            try
            {
                //grab vehicle images with an id matching the vehicle id passed to as the function parameter
                var vehicleImages = db.VehicleImages.Where(x => x.VehicleId == vehicleId).ToList().OrderBy(x => x.Id);
                if (vehicleImages.Count() > 0)
                {
                    var image = vehicleImages.FirstOrDefault();
                    //convert each image from a byte array to a base64 string

                    var imageBytes = image.ImageBytes;
                    var imageBytesToBase64String = Convert.ToBase64String(imageBytes);

                    //return the image i the form of string
                    return(imageBytesToBase64String);
                }
                byte[] errorImageArray = System.IO.File.ReadAllBytes(@"C:\Users\EvanBauer\Music\Git\AutoScout_Production\AutoScout_Production\AutoScout\AutoScout\Content\images\no_image_available.jpg");
                string base64ImageRepresentationError = Convert.ToBase64String(errorImageArray);
                return(base64ImageRepresentationError);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 3
0
        //Delete an unwanted vehicle image for an inventory vehicle
        public void DeleteVehicleImageFromInventoryVehicle(VehicleImage image)
        {
            try
            {
                db.VehicleImages.Remove(image);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <string> GetAllMakes()
        {
            try
            {
                var makes = db.Vehicles.Select(x => x.Make).ToList().Distinct();
                return(makes);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <Vehicle> GetAllVehiclesInInventory(int id)
        {
            try
            {
                var inventoryVehicles = db.Vehicles.Where(x => x.DealershipId == id).ToList();
                return(inventoryVehicles);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 6
0
        public Vehicle GetVehicleFromId(int id)
        {
            try
            {
                var vehicle = db.Vehicles.Find(id);
                return(vehicle);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 7
0
        public Dealership GetDealershipData(int dealershipId)
        {
            try
            {
                var dealership = db.Dealerships.FirstOrDefault(x => x.Id == dealershipId);
                return(dealership);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 8
0
        public IEnumerable <Vehicle> GetAllVehicles()
        {
            try
            {
                var results = db.Vehicles.Where(x => x.Id > 0).OrderBy(x => x.DateCreated).ToList();
                return(results);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 9
0
        public IEnumerable <int> GetAllYears()
        {
            try
            {
                var years = db.Vehicles.Select(x => x.Year).ToList().Distinct();
                return(years);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 10
0
        public IEnumerable <string> GetAllModelsFromMake(string make)
        {
            try
            {
                var models = db.Vehicles.Where(x => x.Make == make).Select(x => x.Model).ToList().Distinct();
                return(models);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 11
0
        public string GetCurrentUserNameFromDealershipId(int dealershipId)
        {
            try
            {
                var companyName = db.Dealerships.FirstOrDefault(x => x.Id == dealershipId).CompanyName;
                return(companyName);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 12
0
        public string GetCurrentUserIdentity()
        {
            try
            {
                var identityId = HttpContext.Current.User.Identity.GetUserId();
                return(identityId);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 13
0
        public Dealership GetDealership(int id)
        {
            try
            {
                var dealership = db.Dealerships.Find(id);
                return(dealership);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 14
0
        //get the profile background image associated with the dealership, converted to basse 64 string
        public string GetDealershipProfileBackgroundAsBase64String(int id)
        {
            try
            {
                //grab the dealership's background byte array, convert it to a base 64 string
                var dealershipBackgroundImageBytes = db.Dealerships.FirstOrDefault(x => x.Id == id).ProfileBackgroundImage;
                var imageBytesToBase64String       = Convert.ToBase64String(dealershipBackgroundImageBytes);

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

                throw (ex);
            }
        }
Ejemplo n.º 15
0
        public void RegisterDealershipAccount(string companyName, string autoScoutIdentityUserId, string email, string city, string state, string zipCode, string phoneNumber, string faxNumber, string notes)
        {
            try
            {
                var db         = new AutoScoutDBContext();
                var dealership = new Dealership {
                    CompanyName = companyName, AutoScoutIdentityUserId = autoScoutIdentityUserId, Email = email, City = city, State = state, ZipCode = zipCode, PhoneNumber = phoneNumber, FaxNumber = faxNumber, Notes = notes
                };
                db.Dealerships.Add(dealership);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 16
0
        public string GetCompanyName(int dealershipId)
        {
            try
            {
                var dealership = db.Dealerships.Find(dealershipId);
                if (dealership != null)
                {
                    var result = dealership.CompanyName;
                    return(result);
                }
                return("");
            } catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 17
0
        //query database to obtain vehicles that match search results
        public ICollection <Vehicle> SearchInventory(string make = "", string model = "", int year = -1, int minPrice = -1, int maxPrice = -1, int minMileage = -1, int maxMileage = -1, string transmission = "", string style = "", string condition = "", int cylinderNumber = -1, string exteriorColor = "")
        {
            try
            {
                //check if price configurations were made in the custom search
                var minPriceSet = minPrice > 0 ? true : false;
                var maxPriceSet = maxPrice > 0 ? true : false;

                //check if mileage configurations were made in the custom search
                var minMileageSet = minMileage > 0 ? true : false;
                var maxMileageSet = maxMileage > 0 ? true : false;

                /*set the price min & max, and the mileage min & max to be used in the query
                 * based on whether custom values were submitted*/
                minPrice   = minPriceSet == true ? minPrice : 0;
                maxPrice   = maxPriceSet == true ? maxPrice : 999999;
                minMileage = minMileageSet == true ? minMileage : 0;
                maxMileage = maxMileageSet == true ? maxMileage : 999999;

                /* query database of vehicles using user submitted search criteria - using Entity Framework */
                var results = db.Vehicles.Where(x => (make != "" ? x.Make == make : x.Make != "") &&
                                                (model != "" ? x.Model == model : x.Model != "") &&
                                                (year > 0 ? x.Year == year : x.Year > 0) &&
                                                (transmission != "" ? x.Transmission == transmission : x.Transmission != "") &&
                                                (style != "" ? x.Style == style : x.Style != "") &&
                                                (cylinderNumber > 0 ? x.CylinderNumber == cylinderNumber : x.CylinderNumber > 0) &&
                                                (exteriorColor != "" ? x.ExteriorColor == exteriorColor : x.ExteriorColor != "") &&
                                                (x.Price > minPrice && x.Price < maxPrice) &&
                                                (x.Mileage > minMileage && x.Mileage < maxMileage)).ToList();

                //return list of vehicles matching criteria
                return(results);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 18
0
        public int GetCurrentUserDealershipIdFromIdentity()
        {
            try
            {
                var identityId = HttpContext.Current.User.Identity.GetUserId();
                if (identityId != null)
                {
                    var dealershipId = db.Dealerships.FirstOrDefault(x => x.AutoScoutIdentityUserId == identityId).Id;
                    return(dealershipId);
                }

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

                throw (ex);
            }
        }
Ejemplo n.º 19
0
        //Assign uploaded images to dealership profile header and icon
        public void AssignProfileImagesToDealership(int dealershipId, HttpPostedFileBase headerImageFile, HttpPostedFileBase iconImageFile)
        {
            try
            {
                var dealership = db.Dealerships.FirstOrDefault(x => x.Id == dealershipId);
                if (dealership != null)
                {
                    if (headerImageFile != null)
                    {
                        //create new byte array of appropriate length
                        var imageBytes = new byte[headerImageFile.ContentLength];

                        //read bytes from input file and convert to byte array, store in image bytes (empty byte array)
                        headerImageFile.InputStream.Read(imageBytes, 0, headerImageFile.ContentLength);

                        dealership.ProfileBackgroundImage = imageBytes;
                    }

                    if (iconImageFile != null)
                    {
                        //create new byte array of appropriate length
                        var imageBytes = new byte[iconImageFile.ContentLength];

                        //read bytes from input file and convert to byte array, store in image bytes (empty byte array)
                        iconImageFile.InputStream.Read(imageBytes, 0, iconImageFile.ContentLength);

                        dealership.Icon = imageBytes;
                    }
                }

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

                throw (ex);
            }
        }
Ejemplo n.º 20
0
        public void DeleteVehicleFromInventory(int vehicleId, int dealershipId)
        {
            try
            {
                var ownerOfVehicleId = db.Vehicles.FirstOrDefault(x => x.Id == vehicleId).DealershipId;
                var currentUserId    = GetCurrentUserDealershipIdFromIdentity();
                if (ownerOfVehicleId == currentUserId)
                {
                    var vehicle = db.Vehicles.FirstOrDefault(x => x.Id == vehicleId);
                    db.Vehicles.Remove(vehicle);
                    db.SaveChanges();
                }
                return;
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 21
0
        public IEnumerable <VehicleImage> GetAllVehicleImages(int id)
        {
            try
            {
                var imagesForVehicle = db.VehicleImages.Where(x => x.VehicleId == id);
                if (imagesForVehicle != null)
                {
                    var result = imagesForVehicle;
                    return(imagesForVehicle.ToList());
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 22
0
        public void SaveDealershipDetails(int id, string companyName, string email, string city, string state, string zipCode, string phoneNumber, string faxNumber, string notes)
        {
            try
            {
                var dealership = db.Dealerships.FirstOrDefault(x => x.Id == id);
                dealership.CompanyName = companyName;
                dealership.Email       = email;
                dealership.City        = city;
                dealership.State       = state;
                dealership.ZipCode     = zipCode;
                dealership.PhoneNumber = phoneNumber;
                dealership.FaxNumber   = faxNumber;
                dealership.Notes       = notes;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 23
0
        //Acquire string of base 64 strings, to pull vehicle images from the db to the view to be rendered in the browser
        public IEnumerable <string> GetImagesConvertedToBase64Strings(int id)
        {
            try
            {
                var result = new List <string>();

                //grab vehicle images with an id matching the vehicle id passed to as the function para,eter
                var vehicleImages = db.VehicleImages.Where(x => x.VehicleId == id).ToList();
                if (vehicleImages.Count > 0)
                {
                    //convert each image from a byte array to a base64 string
                    foreach (var item in vehicleImages)
                    {
                        var imageBytes = item.ImageBytes;
                        var imageBytesToBase64String = Convert.ToBase64String(imageBytes);
                        result.Add(imageBytesToBase64String);
                    }
                }
                else
                {
                    byte[] errorImageArray = System.IO.File.ReadAllBytes(@"C:\Users\EvanBauer\Music\Git\AutoScout_Production\AutoScout_Production\AutoScout\AutoScout\Content\images\no_image_available.jpg");
                    string base64ImageRepresentationError = Convert.ToBase64String(errorImageArray);
                    result.Add(base64ImageRepresentationError);
                }

                //return the images in the form of a list of strings
                return(result);
            }
            catch (Exception ex)
            {
                var errorService = new ErrorService(db);
                errorService.logError(ex);

                throw (ex);
            }
        }
Ejemplo n.º 24
0
        public IEnumerable <Vehicle> GetNewest3Vehicles()
        {
            try
            {
                var results = db.Vehicles.Where(x => x.Id > 0).ToList();
                results.OrderBy(x => x.DateCreated);
                results.Reverse();

                var top3 = new List <Vehicle>();
                for (var i = 0; i < 3; ++i)
                {
                    top3.Add(results[i]);
                }

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

                throw (ex);
            }
        }
Ejemplo n.º 25
0
        //create a new vehicle with parameters given, along with vehicle images associated with the vehicle, and add them to the database
        public void CreateInventoryVehicle(int id, string vin, int mileage, string exteriorColor, string interiorColor, string make, string model, int year, decimal price, string condition, int cylinderNumber, string transmissionType, HttpPostedFileBase[] imageFiles)
        {
            try
            {
                var currentDealershipId = GetCurrentUserDealershipIdFromIdentity();
                var dealership          = db.Dealerships.FirstOrDefault(x => x.Id == currentDealershipId);
                var newVehicle          = new Vehicle
                {
                    VIN            = vin,
                    Mileage        = mileage,
                    ExteriorColor  = exteriorColor,
                    InteriorColor  = interiorColor,
                    Make           = make,
                    Model          = model,
                    Year           = year,
                    Price          = price,
                    Condition      = condition,
                    CylinderNumber = cylinderNumber,
                    Transmission   = transmissionType,
                    DealershipId   = currentDealershipId
                };


                var vehicleImageList = new List <VehicleImage>();
                for (int i = 0; i < imageFiles.Count(); i++)
                {
                    //create new byte array of appropriate length
                    var imageBytes = new byte[imageFiles[i].ContentLength];

                    //read bytes from input file and convert to byte array, store in image bytes (empty byte array)
                    imageFiles[i].InputStream.Read(imageBytes, 0, imageFiles[i].ContentLength);


                    var vehicleImage = new VehicleImage
                    {
                        ImageBytes = imageBytes,
                        VehicleId  = id
                    };

                    vehicleImageList.Add(vehicleImage);
                }

                //Add vehicle to Vehicles table
                db.Vehicles.Add(newVehicle);

                //Add vehicle images to VehicleImages table
                foreach (var item in vehicleImageList)
                {
                    db.VehicleImages.Add(item);
                }

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

                throw (ex);
            }
        }