private static void WalkCustomerRetForAdd(XmlNode CustomerRet) { if (CustomerRet == null) { return; } RotoTrackDb db = new RotoTrackDb(); string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; string EditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; string Name = CustomerRet.SelectSingleNode("./Name").InnerText; if (db.WorkOrders.Any(f => f.WorkOrderNumber == Name)) { WorkOrder wo = db.WorkOrders.First(f => f.WorkOrderNumber == Name); wo.QBListId = ListID; wo.QBEditSequence = EditSequence; db.Entry(wo).State = EntityState.Modified; if (wo != null) { db.SaveChanges(); } } }
private static Item FindOrCreateItem(RotoTrackDb db, string QBListId, string QBEditSequence, string TimeCreated, string TimeModified, string Name, string FullName, string IsActive, string ItemType) { Item o = null; if (db.Items.Any(f => f.QBListId == QBListId)) { o = db.Items.First(f => f.QBListId == QBListId); db.Entry(o).State = EntityState.Modified; } else { o = new Item(); db.Items.Add(o); } o.QBListId = QBListId; o.QBEditSequence = QBEditSequence; DateTime createdDate; if (DateTime.TryParse(TimeCreated, out createdDate)) o.TimeCreated = createdDate; DateTime modifiedDate; if (DateTime.TryParse(TimeModified, out modifiedDate)) o.TimeModified = modifiedDate; o.Name = Name; o.FullName = FullName; o.IsActive = (IsActive == "true") ? true : false; o.ItemType = ItemType; return o; }
public static void UpdateAlreadyExistingWorkOrder(int woId) { RotoTrackDb db = new RotoTrackDb(); WorkOrder wo = db.WorkOrders.Find(woId); if (wo != null) { string response = QBUtils.DoRequest(CustomerDAL.BuildCustomerQueryByWorkorderNum(wo.WorkOrderNumber)); string qbid = CustomerDAL.GetQBIDFromResponse(response); string qbes = CustomerDAL.GetQBEditSequenceFromResponse(response); if ((qbid != "") && (qbes != "")) { wo.QBListId = qbid; wo.QBEditSequence = qbes; db.Entry(wo).State = EntityState.Modified; db.SaveChanges(); } } }
private static void WalkVehicleMileageRetForAdd(XmlNode VehicleMileageRet) { if (VehicleMileageRet == null) { return; } RotoTrackDb db = new RotoTrackDb(); //Get value of Notes--we should have the ServiceEntry GUID encoded in it as well. string seGUID = ""; if (VehicleMileageRet.SelectSingleNode("./Notes") != null) { string Notes = VehicleMileageRet.SelectSingleNode("./Notes").InnerText; seGUID = QBUtils.GetGuidFromNotes(Notes); } string TxnID = ""; if (VehicleMileageRet.SelectSingleNode("./TxnID") != null) { TxnID = VehicleMileageRet.SelectSingleNode("./TxnID").InnerText; } if (seGUID != "" && TxnID != "") { ServiceEntry se = null; if (db.ServiceEntries.Any(f => f.GUID == seGUID)) { se = db.ServiceEntries.First(f => f.GUID == seGUID); } if (se != null) { se.QBListIdForMileage = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } } }
private static void WalkTimeTrackingRetForAdd(XmlNode TimeTrackingRet) { if (TimeTrackingRet == null) { return; } string Duration = TimeTrackingRet.SelectSingleNode("./Duration").InnerText; HoursMinutes hrsMins = GetHoursMinutesFromDuration(Duration); if (hrsMins == null) { return; } RotoTrackDb db = new RotoTrackDb(); string TxnID = ""; string seGUID = ""; string ItemServiceListID = ""; if (TimeTrackingRet.SelectSingleNode("./TxnID") != null) { TxnID = TimeTrackingRet.SelectSingleNode("./TxnID").InnerText; } if (TimeTrackingRet.SelectSingleNode("./Notes") != null) { string Notes = TimeTrackingRet.SelectSingleNode("./Notes").InnerText; seGUID = QBUtils.GetGuidFromNotes(Notes); } XmlNode ItemServiceRef = TimeTrackingRet.SelectSingleNode("./ItemServiceRef"); if (ItemServiceRef != null) { if (ItemServiceRef.SelectSingleNode("./ListID") != null) { ItemServiceListID = ItemServiceRef.SelectSingleNode("./ListID").InnerText; } } if (TxnID != null && seGUID != null && ItemServiceListID != null) { ServiceEntry se = null; if (db.ServiceEntries.Any(f => f.GUID == seGUID)) { se = db.ServiceEntries.First(f => f.GUID == seGUID); } if (se != null) { ServiceDetail sd = db.ServiceDetails.Find(se.ServiceDetailId); if (sd != null) { ServiceType regST = db.ServiceTypes.Find(sd.ServiceTypeId); ServiceType otST = db.ServiceTypes.Find(sd.OTServiceTypeId); if (regST != null && otST != null) { // We always update the regular hours first, so if reg and OT both have the same service list ID, then we need to also check if we already // wrote out the regular hours or not--else we will put both the reg and ot hours into regular hours since we match on reg hours first. // I was going to also look at the actual hours and minutes, but if those are identical, too, then this reduces to the same problem we have // solved here--we just have to assume reg hours are always written first, which they are. Also, I don't want to compare on hours/minutes // because that may fail due to rounding errors. if (ItemServiceListID == regST.QBListId && se.QBListIdForRegularHours == null) { se.QBListIdForRegularHours = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } else if (ItemServiceListID == otST.QBListId && se.QBListIdForOTHours == null) { se.QBListIdForOTHours = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } } } } } }
private void SyncDSRs() { AppendStatus("Syncing DSRs..."); RotoTrackDb db = new RotoTrackDb(); int approvedVal = (int)DSRStatus.Approved; List<DSRLite> dsrList = db.DSRs.Where(f => f.IsSynchronizedWithQB == false && f.statusValue == approvedVal).Select(f => new DSRLite { Id = f.Id, WorkOrderId = f.WorkOrderId, WorkOrderGUID = f.WorkOrderGUID, Created = f.Created, Modified = f.Modified, DateWorked = f.DateWorked, TechnicianId = f.TechnicianId, IsSynchronizedWithQB = f.IsSynchronizedWithQB, statusValue = f.statusValue }).ToList(); foreach (DSRLite dsr in dsrList) { List<ServiceEntry> serviceEntryList = db.ServiceEntries.Where(f => f.DSRId == dsr.Id).ToList(); foreach (ServiceEntry se in serviceEntryList.ToList()) { ServiceDetail sd = db.ServiceDetails.Find(se.ServiceDetailId); if (se.QBListIdForMileage == null) { if (se.Mileage == 0) { SetMileageToNA(se.Id); } else { AddVehicleMileage(se.Id, se.ServiceDetailId); } } if (se.QBListIdForRegularHours == null) { if (se.RegularHours == 0) { SetRegularHoursToNA(se.Id); } else { AddTimeTracking(se.Id, se.ServiceDetailId, sd.ServiceTypeId, se.RegularHours); } } if (se.QBListIdForOTHours == null) { if (se.OTHours == 0) { SetOTHoursToNA(se.Id); } else { AddTimeTracking(se.Id, se.ServiceDetailId, sd.OTServiceTypeId, se.OTHours); } } } // Update status of DSR DSR dsrToUpdate = db.DSRs.Find(dsr.Id); dsrToUpdate.IsSynchronizedWithQB = true; db.Entry(dsrToUpdate).State = EntityState.Modified; db.SaveChanges(); } AppendStatus("Done"); AppendStatus(Environment.NewLine); }
private void SetRegularHoursToNA(int seID) { RotoTrackDb db = new RotoTrackDb(); ServiceEntry se = db.ServiceEntries.Find(seID); se.QBListIdForRegularHours = "N/A"; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); }
private void RemoveDSRTimeAndMileage() { AppendStatus("Removing Deleted DSR Time and Mileage..."); RotoTrackDb db = new RotoTrackDb(); List<DeletedTimeTracking> deletedTimeList = db.DeletedTimeTrackings.Where(f => f.IsSynchronizedWithQB == false).ToList(); foreach (DeletedTimeTracking deletedTime in deletedTimeList) { if (RemoveTimeTracking(deletedTime.Id)) { deletedTime.IsSynchronizedWithQB = true; db.Entry(deletedTime).State = EntityState.Modified; db.SaveChanges(); } } List<DeletedMileageTracking> deletedMileageList = db.DeletedMileageTrackings.Where(f => f.IsSynchronizedWithQB == false).ToList(); foreach (DeletedMileageTracking deletedMileage in deletedMileageList) { if (RemoveVehicleMileage(deletedMileage.Id)) { deletedMileage.IsSynchronizedWithQB = true; db.Entry(deletedMileage).State = EntityState.Modified; db.SaveChanges(); } } // Due to buggy time and mileage handling in QB, remove any deleted time or mileage trackings that still exist. db.Database.ExecuteSqlCommand("delete from MileageTrackings where QBTxnId in (select QBTxnId from DeletedMileageTrackings)"); db.Database.ExecuteSqlCommand("delete from TimeTrackings where QBTxnId in (select QBTxnId from DeletedTimeTrackings)"); AppendStatus("Done"); AppendStatus(Environment.NewLine); }
private bool UpdateWorkOrder(int woID) { RotoTrackDb db = new RotoTrackDb(); WorkOrder wo = db.WorkOrders.Find(woID); XmlDocument doc = WorkOrderDAL.BuildModRq(wo); string response = QBUtils.DoRequest(doc); bool status = WorkOrderDAL.HandleModResponse(response); if (!status) { //Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Failed to update work order for WO#: " + wo.WorkOrderNumber + " ListID: " + wo.QBListId + ". Setting NeedToUpdateQB flag to true to try again."); wo.NeedToUpdateQB = true; db.Entry(wo).State = EntityState.Modified; db.SaveChanges(); return false; } else { return true; } }
private void UpdateInvoiceSubtotal(int woID) { RotoTrackDb db = new RotoTrackDb(); WorkOrder wo = db.WorkOrders.Find(woID); // Do invoice subtotal double invoiceSubtotal = 0.0; if (db.Invoices.Any(f => f.WorkOrderListID == wo.QBListId)) { string query = "select i.TxnId, i.TxnDate, i.WorkOrderListID, i.Subtotal from invoices i inner join (select max(i.id) as id from Invoices i inner join WorkOrders w on w.QBListId = i.WorkOrderListID where i.TxnDate <> '1900-01-01 00:00:00.000' and i.WorkOrderListID = '" + wo.QBListId + "' group by i.TxnId, i.WorkOrderListID) iv on iv.id = i.Id"; List<DistinctInvoice> invoices = db.Database.SqlQuery<DistinctInvoice>(query).ToList(); //List<Invoice> invoiceList = db.Invoices.Where(f => f.WorkOrderListID == wo.QBListId).ToList(); foreach (DistinctInvoice invoice in invoices) { invoiceSubtotal += invoice.Subtotal; wo.InvoiceCreated = invoice.TxnDate; } } wo.InvoiceSubtotal = invoiceSubtotal; if ((wo.CloseStatus == CloseStatus.Warranty) && (wo.InvoiceSubtotal > 0)) { wo.InvoiceSubtotal *= -1.0; } db.Entry(wo).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception ex) { Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Exception occurred: " + ex.ToString() + wo.Id.ToString() + "," + wo.InvoiceCreated.ToShortDateString() + "," + wo.InvoiceSubtotal.ToString() + db.GetValidationErrors().ToString()); throw (ex); } }
private void UpdateEstDollarAmountForWorkOrder(int woID) { RotoTrackDb db = new RotoTrackDb(); WorkOrder wo = db.WorkOrders.Find(woID); string woListID = wo.QBListId; List<TimeTracking> timetrackings; timetrackings = db.TimeTrackings.Where(f => f.QBWorkOrderListID == woListID).ToList(); List<MileageTracking> mileagetrackings; mileagetrackings = db.MileageTrackings.Where(f => f.QBWorkOrderListID == woListID).ToList(); List<BillLine> billLines; billLines = db.BillLines.Where(f => f.WorkOrderListID == woListID).ToList(); List<VendorCreditLine> vendorCreditLines; vendorCreditLines = db.VendorCreditLines.Where(f => f.WorkOrderListID == woListID).ToList(); List<SalesOrderLine> soLines; soLines = db.SalesOrderLines.Where(f => f.WorkOrderListID == woListID).ToList(); var workorders = db.WorkOrders.ToList(); var users = db.UserProfiles.ToList(); var servicetypes = db.ServiceTypes.ToList(); var customers = db.Customers.ToList(); var vehicles = db.Vehicles.ToList(); var mileagerates = db.MileageRates.ToList(); var vendors = db.Vendors.ToList(); var items = db.Items.ToList(); var tt_results = from tt in timetrackings from workorder in workorders.Where(f => f.QBListId == tt.QBWorkOrderListID).DefaultIfEmpty() from customer in customers.Where(f => f.Id == (workorder == null ? -1 : workorder.CustomerId)).DefaultIfEmpty() from user in users.Where(f => f.QBListId == tt.QBEmployeeListID).DefaultIfEmpty() from servicetype in servicetypes.Where(f => f.QBListId == tt.QBServiceTypeListID).DefaultIfEmpty() select new { Id = tt.Id, Job = ((workorder == null) || (customer == null)) ? "" : (customer.Name + ":" + workorder.WorkOrderNumber), Type = "Time", BillableStatus = tt.BillableStatus, Date = tt.DateWorked, Item = (servicetype == null) ? "" : servicetype.Name, Description = (user == null) ? "" : user.FirstName + " " + user.LastName, Unit = tt.HoursWorked + (tt.MinutesWorked / 60.0M), Rate = (servicetype == null) ? 0M : decimal.Parse(servicetype.Price) * 1.0M, Amount = (servicetype == null) ? 0M : decimal.Parse(servicetype.Price) * (tt.HoursWorked + (tt.MinutesWorked / 60.0M)) * 1.0M, SalePrice = (servicetype == null) ? 0M : decimal.Parse(servicetype.Price) * (tt.HoursWorked + (tt.MinutesWorked / 60.0M)) * 1.0M, Comments = "" }; var mileage_results = from mileagetracking in mileagetrackings from workorder in workorders.Where(f => f.QBListId == mileagetracking.QBWorkOrderListID).DefaultIfEmpty() from customer in customers.Where(f => f.Id == (workorder == null ? -1 : workorder.CustomerId)).DefaultIfEmpty() from vehicle in vehicles.Where(f => f.QBListId == mileagetracking.QBVehicleListID).DefaultIfEmpty() from mileagerate in mileagerates.Where(f => f.QBListId == mileagetracking.QBMileageRateListID).DefaultIfEmpty() select new { Id = mileagetracking.Id, Job = ((workorder == null) || (customer == null)) ? "" : (customer.Name + ":" + workorder.WorkOrderNumber), Type = "Mileage", BillableStatus = mileagetracking.BillableStatus, Date = mileagetracking.TripStartDate, Item = (mileagerate == null) ? "" : mileagerate.Name, Description = (vehicle == null) ? "" : vehicle.Name, Unit = mileagetracking.TotalMiles * 1.0M, Rate = (mileagerate == null) ? 0.0M : (mileagerate.Rate * 1.0M), Amount = mileagetracking.BillableAmount * 1.0M, SalePrice = mileagetracking.BillableAmount * 1.0M, Comments = mileagetracking.Notes }; var bill_results = from billline in billLines from workorder in workorders.Where(f => f.QBListId == billline.WorkOrderListID).DefaultIfEmpty() from customer in customers.Where(f => f.Id == (workorder == null ? -1 : workorder.CustomerId)).DefaultIfEmpty() from item in items.Where(f => f.QBListId == billline.ItemListID).DefaultIfEmpty() from vendor in vendors.Where(f => f.QBListId == billline.VendorListID).DefaultIfEmpty() select new { Id = billline.Id, Job = ((workorder == null) || (customer == null)) ? "" : (customer.Name + ":" + workorder.WorkOrderNumber), Type = ((billline.Amount < 0) ? "Credit" : "Bill"), BillableStatus = billline.BillableStatus, Date = billline.BillTxnDate, Item = (item == null) ? "" : item.Name, Description = billline.Description, Unit = ((billline.Quantity == 0 && billline.Amount > 0 && billline.UnitCost > 0) ? (billline.Amount / billline.UnitCost) : billline.Quantity * 1.0M), Rate = billline.UnitCost * 1.0M, Amount = billline.Amount * 1.0M, //SalePrice = ((billline.Amount < 0) ? billline.Amount * 1.0M : 0.0M), SalePrice = CalculateSalePrice(billline, item), Comments = (vendor == null) ? "" : vendor.Name }; var vendor_credit_results = from vendorcreditline in vendorCreditLines from workorder in workorders.Where(f => f.QBListId == vendorcreditline.WorkOrderListID).DefaultIfEmpty() from customer in customers.Where(f => f.Id == (workorder == null ? -1 : workorder.CustomerId)).DefaultIfEmpty() from item in items.Where(f => f.QBListId == vendorcreditline.ItemListID).DefaultIfEmpty() from vendor in vendors.Where(f => f.QBListId == vendorcreditline.VendorListID).DefaultIfEmpty() select new { Id = vendorcreditline.Id, Job = ((workorder == null) || (customer == null)) ? "" : (customer.Name + ":" + workorder.WorkOrderNumber), Type = "Credit", BillableStatus = vendorcreditline.BillableStatus, Date = vendorcreditline.VendorCreditTxnDate, Item = (item == null) ? "" : item.Name, Description = vendorcreditline.Description, Unit = ((vendorcreditline.Quantity == 0 && vendorcreditline.Amount > 0 && vendorcreditline.UnitCost > 0) ? (vendorcreditline.Amount / vendorcreditline.UnitCost) : vendorcreditline.Quantity * 1.0M), Rate = vendorcreditline.UnitCost * -1.0M, Amount = vendorcreditline.Amount * -1.0M, //SalePrice = ((billline.Amount < 0) ? billline.Amount * 1.0M : 0.0M), SalePrice = CalculateSalePrice(vendorcreditline, item) * -1.0M, Comments = (vendor == null) ? "" : vendor.Name }; var so_results = from soline in soLines from workorder in workorders.Where(f => f.QBListId == soline.WorkOrderListID).DefaultIfEmpty() from customer in customers.Where(f => f.Id == (workorder == null ? -1 : workorder.CustomerId)).DefaultIfEmpty() select new { Id = soline.Id, Job = ((workorder == null) || (customer == null)) ? "" : (customer.Name + ":" + workorder.WorkOrderNumber), Type = "Sales Order", BillableStatus = soline.BillableStatus, Date = soline.SalesOrderTxnDate, Item = soline.ItemName, Description = soline.Description, Unit = soline.Quantity * 1.0M, Rate = soline.UnitCost * 1.0M, Amount = soline.Amount * 1.0M, SalePrice = soline.Amount * 1.0M, Comments = "" }; var workordersummaryAll = tt_results .Concat(mileage_results) .Concat(bill_results) .Concat(vendor_credit_results) .Concat(so_results) .AsQueryable(); decimal totalAmount = workordersummaryAll.Sum(f => f.Amount); decimal totalSalePrice = workordersummaryAll.Sum(f => f.SalePrice); wo.EstDollarAmount = (double)totalSalePrice; if ((wo.CloseStatus == CloseStatus.Warranty) && (wo.EstDollarAmount > 0)) { wo.EstDollarAmount *= -1.0; } db.Entry(wo).State = EntityState.Modified; db.SaveChanges(); }
private void SyncVacationAndSickTime() { AppendStatus("Syncing Vacation and Sick Time..."); RotoTrackDb db = new RotoTrackDb(); List<Employee> employees = db.Employees.Where(f => f.IsActive == true).ToList(); foreach (Employee e in employees) { RotoTrackDbUtils.ComputeVacationFields(e); db.Entry(e).State = EntityState.Modified; db.SaveChanges(); } AppendStatus("Done"); AppendStatus(Environment.NewLine); }
private static void WalkCustomerRetForUpdate(XmlNode CustomerRet) { if (CustomerRet == null) return; RotoTrackDb db = new RotoTrackDb(); string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; string EditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; if (db.WorkOrders.Any(f => f.QBListId == ListID)) { WorkOrder wo = db.WorkOrders.First(f => f.QBListId == ListID); wo.QBEditSequence = EditSequence; db.Entry(wo).State = EntityState.Modified; if (wo != null) { db.SaveChanges(); } } }
private void UpdateSiteAndAdditionalInfo(int woID) { RotoTrackDb db = new RotoTrackDb(); WorkOrder wo = db.WorkOrders.Find(woID); XmlDocument doc = SiteAndAdditionalInfoDAL.BuildUpdateRq(wo); string response = QBUtils.DoRequest(doc); bool status = SiteAndAdditionalInfoDAL.HandleResponse(response); if (!status) { //Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Failed to update site and additional info for WO#: " + wo.WorkOrderNumber + " ListID: " + wo.QBListId + ". Setting NeedToUpdateQB flag to true to try again."); wo.NeedToUpdateQB = true; db.Entry(wo).State = EntityState.Modified; db.SaveChanges(); } }
private static void WalkVehicleMileageRetForAdd(XmlNode VehicleMileageRet) { if (VehicleMileageRet == null) return; RotoTrackDb db = new RotoTrackDb(); //Get value of Notes--we should have the ServiceEntry GUID encoded in it as well. string seGUID = ""; if (VehicleMileageRet.SelectSingleNode("./Notes") != null) { string Notes = VehicleMileageRet.SelectSingleNode("./Notes").InnerText; seGUID = QBUtils.GetGuidFromNotes(Notes); } string TxnID = ""; if (VehicleMileageRet.SelectSingleNode("./TxnID") != null) { TxnID = VehicleMileageRet.SelectSingleNode("./TxnID").InnerText; } if (seGUID != "" && TxnID != "") { ServiceEntry se = null; if (db.ServiceEntries.Any(f => f.GUID == seGUID)) { se = db.ServiceEntries.First(f => f.GUID == seGUID); } if (se != null) { se.QBListIdForMileage = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } } }
private static void WalkTimeTrackingRetForAdd(XmlNode TimeTrackingRet) { if (TimeTrackingRet == null) return; string Duration = TimeTrackingRet.SelectSingleNode("./Duration").InnerText; HoursMinutes hrsMins = GetHoursMinutesFromDuration(Duration); if (hrsMins == null) return; RotoTrackDb db = new RotoTrackDb(); string TxnID = ""; string seGUID = ""; string ItemServiceListID = ""; if (TimeTrackingRet.SelectSingleNode("./TxnID") != null) { TxnID = TimeTrackingRet.SelectSingleNode("./TxnID").InnerText; } if (TimeTrackingRet.SelectSingleNode("./Notes") != null) { string Notes = TimeTrackingRet.SelectSingleNode("./Notes").InnerText; seGUID = QBUtils.GetGuidFromNotes(Notes); } XmlNode ItemServiceRef = TimeTrackingRet.SelectSingleNode("./ItemServiceRef"); if (ItemServiceRef != null) { if (ItemServiceRef.SelectSingleNode("./ListID") != null) { ItemServiceListID = ItemServiceRef.SelectSingleNode("./ListID").InnerText; } } if (TxnID != null && seGUID != null && ItemServiceListID != null) { ServiceEntry se = null; if (db.ServiceEntries.Any(f => f.GUID == seGUID)) { se = db.ServiceEntries.First(f => f.GUID == seGUID); } if (se != null) { ServiceDetail sd = db.ServiceDetails.Find(se.ServiceDetailId); if (sd != null) { ServiceType regST = db.ServiceTypes.Find(sd.ServiceTypeId); ServiceType otST = db.ServiceTypes.Find(sd.OTServiceTypeId); if (regST != null && otST != null) { // We always update the regular hours first, so if reg and OT both have the same service list ID, then we need to also check if we already // wrote out the regular hours or not--else we will put both the reg and ot hours into regular hours since we match on reg hours first. // I was going to also look at the actual hours and minutes, but if those are identical, too, then this reduces to the same problem we have // solved here--we just have to assume reg hours are always written first, which they are. Also, I don't want to compare on hours/minutes // because that may fail due to rounding errors. if (ItemServiceListID == regST.QBListId && se.QBListIdForRegularHours == null) { se.QBListIdForRegularHours = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } else if (ItemServiceListID == otST.QBListId && se.QBListIdForOTHours == null) { se.QBListIdForOTHours = TxnID; db.Entry(se).State = EntityState.Modified; db.SaveChanges(); } } } } } }