private void CreateNewProjectCustomers(int projectID, int customerID, int contactID) { //Insert New Record var pCustomer = new Sales_JobMasterList_Customer() { jobID = projectID, cID = customerID, contactName = contactID, isBillTo = true, isInstallOrShipTo = true, isQuoteTo = true }; try { _dbProject.Sales_JobMasterList_Customer.Add(pCustomer); _dbProject.SaveChanges(); } catch (Exception ex) { var s = ex.Message; throw; } }
/** * Type = 1 => Billing * Type = 2 => Quoting * Type = 3 => Shipping */ private void HandleAccount(string companyName, string companyStreet, string companyProvince, string companyPostalCode, string companyCity, string companyCountry, string firstName, string lastName, string phone, string contactID, string intersection, string corner, int misJobID, int employeeNumber, string accountID, int type, string legalName) { try { int customerID = CommonMethods.GetMISID(TableName.Customer, accountID, salesForceProjectID); if (customerID == 0) { /* Add new billing address */ CUSTOMER customer = new CUSTOMER(); customer.NAME = companyName; //customer.LEGALNAME_SAMEAS_NAME = true; if (legalName == null) { customer.LEGALNAME_SAMEAS_NAME = true; customer.LEGAL_NAME = companyName; } else { customer.LEGALNAME_SAMEAS_NAME = false; customer.LEGAL_NAME = legalName;//companyName; } customer.ADDR_1 = companyStreet; customer.ADDR_2 = ""; customer.CITY = companyCity; customer.STATE = companyProvince; customer.ZIPCODE = companyPostalCode; customer.COUNTRY = companyCountry; customer.SalesID = employeeNumber; customer.Sa1ID = employeeNumber; customer.TERRITORY = "6"; //other customer.ACTIVE_FLAG = "Y"; customer.CURRENCY_ID = "CAD"; customer.Intersection = intersection; switch (corner) { case "North West": customer.NorthWest = true; break; case "North East": customer.NorthEast = true; break; case "South West": customer.SouthWest = true; break; case "South East": customer.SouthEast = true; break; } ProjectCompany cp = new ProjectCompany(misJobID); cp.Insert(misJobID, 0, false, false, false); int jcID = SqlCommon.GetNewlyInsertedRecordID(TableName.Sales_JobMasterList_Customer); /* check if the customer has existed */ int rowID = CommonMethods.GetCompanyMISID(TableName.Customer, accountID); if (rowID == 0) { //if it is not existent rowID = CreateCustomer(customer, jcID); } if (rowID > 0) { CommonMethods.InsertToMISSalesForceMapping(TableName.Customer, accountID, rowID.ToString(), salesForceProjectID); } HandleAccountContact(misJobID, jcID, contactID, rowID, firstName, lastName, phone, accountID, type); } else { CUSTOMER customer = _db.CUSTOMERs.FirstOrDefault(x => x.ROWID == customerID); customer.NAME = companyName; //customer.LEGALNAME_SAMEAS_NAME = true; if (legalName == null) { customer.LEGALNAME_SAMEAS_NAME = true; customer.LEGAL_NAME = companyName; } else { customer.LEGALNAME_SAMEAS_NAME = false; customer.LEGAL_NAME = legalName;//companyName; } customer.ADDR_1 = companyStreet; customer.ADDR_2 = ""; customer.CITY = companyCity; customer.STATE = companyProvince; customer.ZIPCODE = companyPostalCode; customer.COUNTRY = companyCountry; customer.SalesID = employeeNumber; customer.Sa1ID = employeeNumber; customer.TERRITORY = "6"; //other customer.ACTIVE_FLAG = "Y"; customer.CURRENCY_ID = "CAD"; customer.Intersection = intersection; switch (corner) { case "North West": customer.NorthWest = true; break; case "North East": customer.NorthEast = true; break; case "South West": customer.SouthWest = true; break; case "South East": customer.SouthEast = true; break; } _db.Entry(customer).State = EntityState.Modified; _db.SaveChanges(); Sales_JobMasterList_Customer sales_JobMasterList_Customer = _db.Sales_JobMasterList_Customer.FirstOrDefault(x => x.jobID == misJobID && x.cID == customer.ROWID); if (sales_JobMasterList_Customer != null) { HandleAccountContact(misJobID, sales_JobMasterList_Customer.jcID, contactID, customerID, firstName, lastName, phone, accountID, type); } } LogMethods.Log.Debug("HandleAccount:Debug:" + "Done"); } catch (Exception e) { LogMethods.Log.Error("HandleAccount:Error:" + e.Message); } }
private void UpdateSales_JobMasterList_Customer(int jcID, int jobID, int contactID, int customerID, int type) { try { var sales_JobMasterList_Customers = _db.Sales_JobMasterList_Customer.Where(x => x.jobID == jobID).ToList(); if (sales_JobMasterList_Customers.Any()) { foreach (var element in sales_JobMasterList_Customers) { switch (type) { case 1: element.isBillTo = false; break; case 2: element.isQuoteTo = false; break; case 3: element.isInstallOrShipTo = false; break; default: break; } _db.Entry(element).State = EntityState.Modified; } _db.SaveChanges(); } Sales_JobMasterList_Customer sales_JobMasterList_Customer = _db.Sales_JobMasterList_Customer.FirstOrDefault(x => x.jcID == jcID); if (sales_JobMasterList_Customer != null) { switch (type) { case 1: sales_JobMasterList_Customer.isBillTo = true; break; case 2: sales_JobMasterList_Customer.isQuoteTo = true; break; case 3: sales_JobMasterList_Customer.isInstallOrShipTo = true; break; default: break; } sales_JobMasterList_Customer.contactName = contactID; sales_JobMasterList_Customer.cID = customerID; _db.Entry(sales_JobMasterList_Customer).State = EntityState.Modified; _db.SaveChanges(); } LogMethods.Log.Debug("UpdateSales_JobMasterList_Customer:Debug:" + "Done"); } catch (Exception e) { LogMethods.Log.Error("UpdateSales_JobMasterList_Customer:Error:" + e.Message); } }