/// <summary> /// Save all costs to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ServiceInformationTDS serviceInformationChanges = (ServiceInformationTDS)Data.GetChanges(); if (serviceInformationChanges.CostInformation.Rows.Count > 0) { ServiceInformationServiceCostGateway serviceInformationServiceCostGateway = new ServiceInformationServiceCostGateway(serviceInformationChanges); foreach (ServiceInformationTDS.CostInformationRow row in (ServiceInformationTDS.CostInformationDataTable)serviceInformationChanges.CostInformation) { // Insert new costs if ((!row.Deleted) && (!row.InServiceCostDatabase)) { // new values int serviceId = row.ServiceID; int refId = row.RefID; string newPartNumber = serviceInformationServiceCostGateway.GetPartNumber(serviceId, refId); string newPartName = serviceInformationServiceCostGateway.GetPartName(serviceId, refId); string newVendor = serviceInformationServiceCostGateway.GetVendor(serviceId, refId); decimal newCost = serviceInformationServiceCostGateway.GetCost(serviceId, refId); int? noteId = serviceInformationServiceCostGateway.GetNoteID(serviceId, refId); ServicesCost servicesCost = new ServicesCost(null); servicesCost.InsertDirect(serviceId, refId, newPartNumber, newPartName, newVendor, newCost, row.Deleted, row.COMPANY_ID, noteId); } // Update costs if ((!row.Deleted) && (row.InServiceCostDatabase)) { int serviceId = row.ServiceID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // original values string originalPartNumber = serviceInformationServiceCostGateway.GetPartNumberOriginal(serviceId, refId); string originalPartName = serviceInformationServiceCostGateway.GetPartNameOriginal(serviceId, refId); string originalVendor = serviceInformationServiceCostGateway.GetVendorOriginal(serviceId, refId); decimal originalCost = serviceInformationServiceCostGateway.GetCostOriginal(serviceId, refId); int? originalNoteId = serviceInformationServiceCostGateway.GetNoteIDOriginal(serviceId, refId); // new values string newPartNumber = serviceInformationServiceCostGateway.GetPartNumber(serviceId, refId); string newPartName = serviceInformationServiceCostGateway.GetPartName(serviceId, refId); string newVendor = serviceInformationServiceCostGateway.GetVendor(serviceId, refId); decimal newCost = serviceInformationServiceCostGateway.GetCost(serviceId, refId); int? newNoteId = serviceInformationServiceCostGateway.GetNoteID(serviceId, refId); ServicesCost servicesCost = new ServicesCost(null); servicesCost.UpdateDirect(serviceId, refId, originalPartNumber, originalPartName, originalVendor, originalCost, originalDeleted, originalCompanyId, originalNoteId, serviceId, refId, newPartNumber, newPartName, newVendor, newCost, originalDeleted, originalCompanyId, newNoteId); } // Deleted costs if ((row.Deleted) && (row.InServiceCostDatabase)) { ServicesCost servicesCost = new ServicesCost(null); servicesCost.DeleteDirect(row.ServiceID, row.RefID, row.COMPANY_ID); } } } }
/// <summary> /// Save all services to database (direct) /// </summary> /// <param name="serviceId">serviceId</param> /// <param name="companyId">companyId</param> public void Save(int serviceId, int companyId) { ServicesAddRequestTDS servicesAddRequestTDS = (ServicesAddRequestTDS)Data.GetChanges(); if (servicesAddRequestTDS.CostInformation.Rows.Count > 0) { ServicesAddRequestCostInformationGateway servicesAddRequestCostInformationGateway = new ServicesAddRequestCostInformationGateway(servicesAddRequestTDS); foreach (ServicesAddRequestTDS.CostInformationRow row in (ServicesAddRequestTDS.CostInformationDataTable)servicesAddRequestTDS.CostInformation) { // Insert new costs if (!row.Deleted) { // new values int refId = row.RefID; int tempServiceId = row.ServiceID; string newPartNumber = servicesAddRequestCostInformationGateway.GetPartNumber(tempServiceId, refId); string newPartName = servicesAddRequestCostInformationGateway.GetPartName(tempServiceId, refId); string newVendor = servicesAddRequestCostInformationGateway.GetVendor(tempServiceId, refId); decimal newCost = servicesAddRequestCostInformationGateway.GetCost(tempServiceId, refId); ServicesCost servicesCost = new ServicesCost(null); servicesCost.InsertDirect(serviceId, refId, newPartNumber, newPartName, newVendor, newCost, row.Deleted, row.COMPANY_ID, null); } } } }