public int UpdateJobProgress(JobProgress pJobProgress) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // var qry = from p in dataContext.JobProgresses where p.JobGUID == pJobProgress.JobGUID && p.JobStatus == 1 select p; // var item = qry.Single(); // item.StartTime = pJobProgress.StartTime; // item.LastModifiedBy = pJobProgress.LastModifiedBy; // return dataContext.SaveChanges(); //} JobProgress _jobProgress = GetJobProgressMismatch(new Guid(pJobProgress.JobGUID.ToString()), 1); _jobProgress.StartTime = pJobProgress.StartTime; _jobProgress.LastModifiedBy = pJobProgress.LastModifiedBy; _jobProgress.LastModifiedDate = DateTime.UtcNow; SqlParameter[] Param = new SqlParameter[4]; Param[0] = new SqlParameter("@pJobProgressGUID", SqlDbType.UniqueIdentifier); Param[0].Value = _jobProgress.JobProgressGUID; Param[1] = new SqlParameter("@pStartTime", SqlDbType.DateTime); Param[1].Value = (object)_jobProgress.StartTime ?? DBNull.Value; Param[2] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[2].Value = (object)_jobProgress.LastModifiedDate ?? DBNull.Value; Param[3] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[3].Value = (object)_jobProgress.LastModifiedBy ?? DBNull.Value; return context.Database.ExecuteSqlCommand("Update JobProgress set StartTime=@pStartTime,LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy where JobProgressGUID=@pJobProgressGUID", Param); } catch (Exception exception) { return 0; } }
public int InsertJobProgressWithDuration(JobProgress pJobProgress) { int result = 0; ; try { JobProgress _jobProgress = new JobProgress(); _jobProgress.JobProgressGUID = Guid.NewGuid(); _jobProgress.JobGUID = pJobProgress.JobGUID; _jobProgress.JobStatus = pJobProgress.JobStatus; _jobProgress.JobSubStatus = pJobProgress.JobSubStatus; _jobProgress.StartTime = pJobProgress.StartTime; _jobProgress.Duration = pJobProgress.Duration; _jobProgress.Latitude = pJobProgress.Latitude; _jobProgress.Longitude = pJobProgress.Longitude; _jobProgress.LastModifiedDate = DateTime.UtcNow; _jobProgress.LastModifiedBy = pJobProgress.LastModifiedBy; if (pJobProgress.LocationMismatch != null) { _jobProgress.LocationMismatch = pJobProgress.LocationMismatch; } //context.JobProgresses.Add(_jobProgress); //result = Save(); SqlParameter[] Param = new SqlParameter[11]; Param[0] = new SqlParameter("@pJobProgressGUID", SqlDbType.UniqueIdentifier); Param[0].Value = _jobProgress.JobProgressGUID; Param[1] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[1].Value = (object)_jobProgress.JobGUID ?? DBNull.Value; Param[2] = new SqlParameter("@pJobStatus", SqlDbType.Int); Param[2].Value = (object)_jobProgress.JobStatus ?? DBNull.Value; Param[3] = new SqlParameter("@pJobSubStatus", SqlDbType.Int); Param[3].Value = (object)_jobProgress.JobSubStatus ?? DBNull.Value; Param[4] = new SqlParameter("@pStatusNote", SqlDbType.NVarChar, -1); Param[4].Value = (object)_jobProgress.StatusNote ?? DBNull.Value; Param[5] = new SqlParameter("@pStartTime", SqlDbType.DateTime); Param[5].Value = (object)_jobProgress.StartTime ?? DBNull.Value; //Param[6] = new SqlParameter("@pLocationMismatch", SqlDbType.Bit); //Param[6].Value = (object)_jobProgress.LocationMismatch ?? DBNull.Value; Param[6] = new SqlParameter("@pDuration", SqlDbType.Float); Param[6].Value = (object)_jobProgress.Duration ?? DBNull.Value; Param[7] = new SqlParameter("@pLatitude", SqlDbType.Float); Param[7].Value = (object)_jobProgress.Latitude ?? DBNull.Value; Param[8] = new SqlParameter("@pLongitude", SqlDbType.Float); Param[8].Value = (object)_jobProgress.Longitude ?? DBNull.Value; Param[9] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[9].Value = (object)_jobProgress.LastModifiedDate ?? DBNull.Value; Param[10] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[10].Value = (object)_jobProgress.LastModifiedBy ?? DBNull.Value; result = context.Database.ExecuteSqlCommand("insert into JobProgress(JobProgressGUID,JobGUID,JobStatus,JobSubStatus,StatusNote," + "StartTime,Duration,Latitude,Longitude,LastModifiedDate,LastModifiedBy)values(@pJobProgressGUID,@pJobGUID,@pJobStatus,@pJobSubStatus,@pStatusNote," + "@pStartTime,@pDuration,@pLatitude,@pLongitude,@pLastModifiedDate,@pLastModifiedBy)", Param); } catch (System.Exception ex) { throw ex; } return result; }