// update public int Update(RecordRequestModel model, int ID) { int uid = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.EVA_Record_Update" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@RecordID", ID); paramCollection.AddWithValue("@WebsiteId", model.WebsiteId); }); foreach (ValueRequestModel item in model.Values) { _ValueServices.Update(item, ID); } return(uid); }
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; })); }
// create public int Insert(RecordRequestModel model) { int recordID = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.EVA_Record_Insert_two" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@EntityID", model.EntityId); paramCollection.AddWithValue("@WebsiteId", model.WebsiteId); paramCollection.AddWithValue("@AttributeId", model.AttributeId); foreach (ValueRequestModel item in model.Values) { if (item.AttributeId == 136) { paramCollection.AddWithValue("@Value", item.ValueString); break; } } SqlParameter p = new SqlParameter("@OID", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@OID"].Value.ToString(), out recordID); } ); if (recordID > 0) { //ParseValues _ParseValues = new ParseValues(); //_ParseValues.ParseEAVValues(model, recordID); //ParseRecordMedia _ParseRecordMedia = new ParseRecordMedia(); //_ParseRecordMedia.ParseMedia(model, recordID); foreach (ValueRequestModel item in model.Values) { _ValueServices.Insert(item, recordID); } if (model.Medias != null) { var x = 0; foreach (MediaRequestModel media in model.Medias) { int MediaID = _MediaServices.InsertMedia(media); RecordMediaRequestModel RMR = new RecordMediaRequestModel(); if (x == 0) { RMR.IsCoverPhoto = true; } else { RMR.IsCoverPhoto = false; } RMR.RecordID = recordID; RMR.MediaID = MediaID; InsertRecordMedia(RMR); x++; } } DealerIndex indexModel = new DealerIndex(); indexModel.name = "TEST DEALER"; indexModel.dealer_id = 123456; indexModel.zip_code = 92805; _DealerIndexService.IndexDealer(indexModel); } return(recordID); }