public ActionResult updateAttendance() { var listUpdateJSON = Request["sessionId"]; var listUpdate = JsonConvert.DeserializeObject <List <updateStatus> >(listUpdateJSON); using (var transaction = new TransactionScope()) { using (QUANGHANHABCEntities db = new QUANGHANHABCEntities()) { foreach (var item in listUpdate) { DiemDanh_NangSuatLaoDong dn = new DiemDanh_NangSuatLaoDong(); dn.MaDiemDanh = Int32.Parse(item.maDD); dn.MaNV = item.maNV; dn.DiLam = item.status; //if (item.timeAttendance != "") //{ // dn.ThoiGianThucTeDiemDanh = DateTime.ParseExact(item.timeAttendance, "M/d/yyyy hh:mm:ss", null); //} dn.MaDonVi = item.maDV; dn.LyDoVangMat = item.reason; dn.GhiChu = item.description; dn.CaDiemDanh = 1; dn.NgayDiemDanh = Convert.ToDateTime("2019-09-10"); db.Entry(dn).State = EntityState.Modified; } db.SaveChanges(); transaction.Complete(); } } return(Json(new { success = true, data = listUpdateJSON }, JsonRequestBehavior.AllowGet)); }
public void UpdateNSLD( string intCa, string[] MaDiemDanhs, string[] NangSuatLaoDongs, string[] HeSoChiaLuongs, string[] Luongs, string[] DuBaoNguyCos, string[] GiaiPhapNguyCos, string date) { int length = MaDiemDanhs.Length; using (QUANGHANHABCEntities db = new QUANGHANHABCEntities()) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { for (int i = 0; i < length; i++) { int MaDiemDanh = Convert.ToInt32(MaDiemDanhs[i]); DiemDanh_NangSuatLaoDong f = db.DiemDanh_NangSuatLaoDong.FirstOrDefault(x => x.MaDiemDanh == MaDiemDanh); f.NangSuatLaoDong = Convert.ToDouble(String.IsNullOrEmpty(NangSuatLaoDongs[i]) ? "0" : NangSuatLaoDongs[i]); f.HeSoChiaLuong = Convert.ToDouble(String.IsNullOrEmpty(HeSoChiaLuongs[i]) ? "0" : HeSoChiaLuongs[i]); f.Luong = Convert.ToDouble(String.IsNullOrEmpty(Luongs[i]) ? "0" : Luongs[i]); f.DuBaoNguyCo = DuBaoNguyCos[i]; f.GiaiPhapNguyCo = GiaiPhapNguyCos[i]; db.SaveChanges(); } transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } } }
public async Task FetchAndUpdateDatabase(DateTime time) { using (DIEMDANHAPIEntities db = new DIEMDANHAPIEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { // IDENTIFY THE NEXT TIME POINT IF SUCCESSS int timePoint = handler.getTimeLines(time); // FETCH API Result dataReceived = await handler.fetchData(time); // int headerIDMin = headerDAO.getFirstSuccessfullyFetch(dataReceived.dateFetching, dataReceived.Session); // headerDAO.Insert(dataReceived); // if (dataReceived.success) { int currenHeaderID = headerDAO.getHeader(dataReceived.dateFetching, dataReceived.Session, dataReceived.actualTimeFetching); if (headerIDMin == -1) { headerIDMin = currenHeaderID; headerDetailDAO.Insert(headerIDMin); } // var listHaveNotAdded = attendanceDAO.getUnExistItemList(dataReceived.data, headerIDMin); List <DiemDanh_NangSuatLaoDong> attendanceList = new List <DiemDanh_NangSuatLaoDong>(); foreach (var item in listHaveNotAdded) { DiemDanh_NangSuatLaoDong ddEntity = new DiemDanh_NangSuatLaoDong(); ddEntity.HeaderID = headerIDMin; ddEntity.MaNV = item.MaNhanVien; ddEntity.ActualHeaderFetched = currenHeaderID; ddEntity.DiLam = true; ddEntity.isFilledFromAPI = true; ddEntity.isChangedManually = false; ddEntity.ThoiGianXuongLo = item.startTime; ddEntity.ThoiGianLenLo = item.endTime; attendanceList.Add(ddEntity); } attendanceDAO.Insert(attendanceList); DateTime nextTimePoint; if (timePoint == 5) { // next 2 AM morning nextTimePoint = new DateTime(time.Year, time.Month, time.Day + 1, 2, 0, 0); } else { nextTimePoint = new DateTime(time.Year, time.Month, time.Day, handler.timelinesHours[timePoint], handler.timelinesMinutes[timePoint], 0); } timer.Interval = nextTimePoint.Subtract(time).Seconds; } else { // 10 minutes each until successfully fetch timer.Interval = 10 * 1000 * 60; } transaction.Commit(); } catch (Exception ex) { WriteToFile(ex.Message); transaction.Rollback(); } } } }