public IActionResult Add(Team_Message model) { model.Createtime = DateTime.Now.ToLocalTime().ToDateTime(); model.Inbound_Date = DateTime.Now.ToShortDateString().ToDateTime(); var da = new Team_Message_Da(); da.Insert(model); return(SuccessMessage("添加成功!")); }
private bool Import(string excelPath) { try { var dataTableT = ExcelHelper.ToEntityList <Team_Message>(excelPath); //将实体类数据插入数据库;之前要进行查重.将可以导入的数据存为新的实体类 var data1 = new List <Team_Message>(); var da = new Team_Message_Da(); List(null, 0, 0); foreach (var item in dataTableT) { data1.Add(item); foreach (var item1 in list) { if ((item.Equipment_Numbers == item1.Equipment_Numbers) || (item.Id == item1.Id)) { data1.Remove(item); break; } } } if (data1.Count != 0) { foreach (var item2 in data1) { item2.Createtime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd").ToDateTime(); item2.Inbound_Date = item2.Inbound_Date.ToString("yyyy-MM-dd").ToDateTime(); da.Insert(item2); } return(true); } else { return(false); } } catch (Exception e) { return(false); } }