public ActionResult Add() { try { var StartTime = Convert.ToDateTime(Request["AddStartTime"]); var ClassName = Request["AddClassName"].ToString().Trim(); //string[] CardId = Request["CardId"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] AddInfo = Request["AddInfo"].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] info; if (AddInfo.Length > 0) { foreach (var item in AddInfo) { info = item.Split('-'); ClockBatch model = new ClockBatch { guid = Guid.NewGuid(), EmployeeName = info[1], CardId = info[0].Trim(), ClassName = ClassName, StartClockTime = StartTime, LastClockTime = Convert.ToDateTime("2000-1-1 00:00"), ClockState = false, FailedReason = "新增的数据,还没有打卡记录!" + DateTime.Now.ToString(), flag = true }; Db.ClockBatch.Add(model); Db.Entry <ClockBatch>(model).State = EntityState.Added; } } if (Db.SaveChanges() > 0) { return(Json("OK")); } else { return(Json("添加失败")); } } catch (Exception ex) { return(Json($"添加失败,请检查数据格式,使用英文符号!异常信息:{ex}")); } }
public int Delete(int id, byte[] timeStamp, bool persist = true) { var entry = GetEntryFromChangeTracker(id); if (entry != null) { if (entry.TimeStamp == timeStamp) { return(Delete(entry, persist)); } throw new Exception("Unable to delete due to concurrency violation"); } Db.Entry(new T { Id = id, TimeStamp = timeStamp }).State = EntityState.Deleted; return(persist ? SaveChanges() : 0); }