i have scenario in asp.net mvc application upload excel file multiple records, display them in grid / table.
inserting these records database, validate them against procedure, edit errors , re-validate again.
how can group records user upload enable user retrieve specific records when need re-validate?
example:
user a uploads , user b uploads, records written database, how can user his/her specific records fro specific time , upload.
how can manage in asp.net mvc application writes sql server database. write domain name of user database on each upload, if user uploads twice in specific time-frame.
basically asking how can manage record state , make sure users records have uploaded @ specific time. using c#, asp.net mvc , entity framework write database.
please see code below , please advise how can make application more flexible.
public actionresult validateclaims() { list<cleansupplierclaim> supplierclaimsdata = tempdata["supplierclaimsdata"] list<cleansupplierclaim>; //db.cleansupplierclaims.tolist(); //(list<cleansupplierclaim>)tempdata["claimsresponse"];//// //= new list<supplierclaimsuploaddisplaylist>(); cleansupplierclaimdata supplierclaimuplaod = new cleansupplierclaimdata(); var sqlconnection = "data source=wmvsql02;initial catalog=embrace;integrated security=true;"; using (sqlconnection conn = new sqlconnection(sqlconnection)) { try { foreach (var claim in supplierclaimsdata) { sqlcommand cmd = new sqlcommand(); cmd.commandtimeout = 60; sqldatareader reader; cmd.commandtext = "crm.supplier_claim_upload"; cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("@invoice", sqldbtype.nvarchar).value = claim.line_number; cmd.parameters.add("@amount", sqldbtype.decimal).value = claim.total_claim; cmd.connection = conn; //cmd.commandtimeout = 1; conn.open(); reader = cmd.executereader(); while (reader.read()) { claim.st_key = reader.getstring(reader.getordinal("st_key")); claim.error_1 = reader.getstring(reader.getordinal("error1")); string linenumberdoesnotexist = "error: invoice line number not exist"; if (claim.error_1.startswith(linenumberdoesnotexist)) { continue; } claim.warning = reader.getstring(reader.getordinal("warning")); claim.error_2 = reader.getstring(reader.getordinal("error2")); var officialusername = tempdata["user"]; claim.domain_username = officialusername.tostring(); random rnd = new random(); int nextnumber = rnd.next(); if (claim.st_key != null && string.isnullorempty(claim.warning) && string.isnullorempty(claim.error_1) && string.isnullorempty(claim.error_2)) { db.gpclaimsreadytoimports.add(new gpclaimsreadytoimport { id = claim.id, st_key = claim.st_key, warning = claim.warning, action = claim.action, claim_reference = claim.claimreference, currency = claim.currency, error_1 = claim.error_1, error_2 = claim.error_2, line_numebr = claim.line_number, total_claim = claim.total_claim, domain_username = claim.domain_username, datecreated = datetime.now, importflag = true, readyforimport = true }); db.savechanges(); } else { db.cleansupplierclaims.add(new cleansupplierclaim { id = claim.id, st_key = claim.st_key, warning = claim.warning, action = claim.action, claimreference = claim.claimreference, currency = claim.currency, error_1 = claim.error_1, error_2 = claim.error_2, line_number = claim.line_number, total_claim = claim.total_claim, domain_username = claim.domain_username, datecreated = datetime.now, importflag = false, readyforimport = false, }); db.savechanges(); } } } } } }
one way adding new table database, uploadsession
(for example). table represents unique upload session made user. table have id
column (auto generated identity), column user , column time. in existing table, add uploadsessionid
column foreign key id
column in uploadsession
. when upload data, create row in uploadsession
table, generated id, , assign records insert existing table.
when user requests records he/she uploaded @ specific time, query uploadsession
table find matching session id, query existing table records matching session id.
Comments
Post a Comment