// list by ID
        public EVA_Entity GetByID(int id)
        {
            EVA_Entity p = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.EVA_Entity_SelectByID"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@ID", id);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    p = new EVA_Entity();

                    int startingIndex = 0;    //startingOrdinal

                    p.ID         = reader.GetSafeInt32(startingIndex++);
                    p.Name       = reader.GetSafeString(startingIndex++);
                    p.Slug       = reader.GetSafeString(startingIndex++);
                    p.WebsiteId  = reader.GetSafeInt32(startingIndex++);
                    p.Attributes = new List <EVA_Attribute>();
                }
                else if (set == 1)
                {
                    EVA_Attribute x   = new EVA_Attribute();
                    int startingIndex = 0;    //startingOrdinal

                    x.ID          = reader.GetSafeInt32(startingIndex++);
                    x.Name        = reader.GetSafeString(startingIndex++);
                    x.Slug        = reader.GetSafeString(startingIndex++);
                    x.Description = reader.GetSafeString(startingIndex++);
                    int TypeID    = reader.GetSafeInt32(startingIndex++);
                    x.DataType    = (AttributesDataType)TypeID;
                    x.WebsiteId   = reader.GetSafeInt32(startingIndex++);
                    x.IsRequired  = reader.GetSafeBool(startingIndex++);
                    x.ShowOnIndex = reader.GetSafeBool(startingIndex++);

                    p.Attributes.Add(x);
                }
            }
                                    );

            return(p);
        }
        // list by User Name
        public EVA_Entity GetBySlug(string slug)
        {
            EVA_Entity item = new EVA_Entity();

            DataProvider.ExecuteCmd(GetConnection, "dbo.EVA_Entity_SelectBySlug"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Slug", slug);
            }, map : delegate(IDataReader reader, short set)
            {
                int startingIndex = 0;    //startingOrdinal

                item.ID        = reader.GetSafeInt32(startingIndex++);
                item.Name      = reader.GetSafeString(startingIndex++);
                item.Slug      = reader.GetSafeString(startingIndex++);
                item.WebsiteId = reader.GetSafeInt32(startingIndex++);
            }
                                    );

            return(item);
        }
        public Task <int> parseCSV(AdminImportRequestModel model)
        {
            return(Task.Run(() =>
            {
                //Use downloadDate because when the file gets downloaded it is saved by date and then this function runs
                //Directly after the file has been downloaded
                String downloadDate = DateTime.Now.ToString("dd.MM.yyyy");
                string destination = AppDomain.CurrentDomain.BaseDirectory + "dtc/" + downloadDate + "/dtcinventory.txt";
                _AdminImport = model;

                EVA_Entity Entity = _entityService.GetByID(model.EntityId);

                using (var sr = new StreamReader(destination))
                {
                    var csv = new CsvReader(sr);
                    csv.Configuration.Delimiter = "\t";
                    csv.Configuration.IgnoreHeaderWhiteSpace = true;
                    var records = csv.GetRecords <TestDTCDealerRequestModel>();


                    foreach (var record in records)
                    {
                        if (record == null)
                        {
                            break;
                        }
                        //Im making a new instance of RRM which is going to get passed in at the end
                        RecordRequestModel RRM = new RecordRequestModel();
                        RRM.EntityId = this._AdminImport.EntityId;
                        RRM.WebsiteId = this._AdminImport.WebsiteId;
                        RRM.AttributeId = 136;
                        RRM.Values = new List <ValueRequestModel>();
                        RRM.Medias = new List <MediaRequestModel>();

                        TestDTCDealerRequestModel VehicleRM = new TestDTCDealerRequestModel();

                        PropertyInfo[] Y = VehicleRM.GetType().GetProperties();

                        for (var p = 0; p < Y.Length; p++)
                        {
                            string slug = UtilityService.camelCaseToDash(Y[p].Name);

                            foreach (var attribute in Entity.Attributes)
                            {
                                if (slug == attribute.Slug)
                                {
                                    ValueRequestModel ValueRm = new ValueRequestModel();
                                    ValueRm.AttributeId = attribute.ID;
                                    ValueRm.ValueString = record.GetType().GetProperty(Y[p].Name).GetValue(record, null).ToString();
                                    System.Diagnostics.Debug.WriteLine(ValueRm.ValueString);
                                    RRM.Values.Add(ValueRm);
                                }
                            }
                        }

                        //Within the CSV there are numbers seperated by pipes which are the img number
                        //Here we seperate them on the pipe and insert them into the url
                        if (record.Images != null)
                        {
                            string[] RecordMediaArray = record.Images.Split('|');
                            var x = 0;
                            foreach (string recordMediaPath in RecordMediaArray)
                            {
                                RecordMediaRequestModel RecordMedia = new RecordMediaRequestModel();
                                RecordMedia.FileName = "http://img.leaddelivery.net/images/" + record.VIN + "/Original/" + recordMediaPath + ".jpg";
                                RecordMedia.MediaType = "3";
                                RecordMedia.FileType = "image/jpeg";
                                System.Diagnostics.Debug.WriteLine(RecordMedia.FileName);
                                //Setting first image equal to the cover photo
                                if (x == 0)
                                {
                                    RecordMedia.IsCoverPhoto = true;
                                }
                                else
                                {
                                    RecordMedia.IsCoverPhoto = false;
                                }

                                RRM.Medias.Add(RecordMedia);

                                x++;
                            }
                        }
                        //The RRM final gets inserted into the ProcessAsync Task
                        _InsertRecord.ProcessAsync(RRM);
                    }
                }
                return 5;
            }));
        }