private void InsertIntoDailyFiles(DailyFile dailyFile, string root, int newname) { dailyFile.FilePath = root + newname + ".xls"; string con = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dailyFile.FilePath + ";Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';"); //string con2 = // (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\File\Bank.xls;Extended Properties='Excel 12.0 Xml; HDR = YES; IMEX = 1';"); BL bl = new BL(con); DataTable dtw = bl.GetTable("select * from [Sheet1$]"); List<DailyFileDetails> list = new List<DailyFileDetails>(); foreach (DataRow row in dtw.Rows) { if (row[6].ToString() != "") { int empid = Convert.ToInt32(row[4]); if (Convert.ToDecimal(row[6]) > 0) { var firstOrDefault = _db.Employees.FirstOrDefault(x => x.Code == (empid)); if (firstOrDefault != null) dailyFile.DailyFileDetailses.Add(new DailyFileDetails() { Net = Convert.ToDecimal(row[6]), EmployeeId = firstOrDefault.Id, DailyFileId = dailyFile.Id, Employee = firstOrDefault }); } } } dailyFile.EmployeesNumber = dailyFile.DailyFileDetailses.Count; dailyFile.FileTotalAmount = dailyFile.DailyFileDetailses.Sum(x => x.Net); _db.DailyFiles.Add(dailyFile); _db.SaveChanges(); }
public IHttpActionResult PutDailyFile(DailyFile dailyFile) { int id = dailyFile.Id; dailyFile.CreatedDate = DateTime.UtcNow; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != dailyFile.Id) { return BadRequest(); } _db.Entry(dailyFile).State = EntityState.Modified; try { _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DailyFileExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }