/// <summary> /// Copy from legacy to new record For the table of HET_City /// </summary> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="city"></param> /// <param name="systemId"></param> /// <param name="maxCityIndex"></param> private static void CopyToInstance(DbAppContext dbContext, HetsCity oldObject, ref City city, string systemId, ref int maxCityIndex) { try { if (city != null) { return; } city = new City { Id = ++maxCityIndex }; // *********************************************** // set the city name // *********************************************** string tempName = ImportUtility.CleanString(oldObject.Name); if (string.IsNullOrEmpty(tempName)) { return; } tempName = ImportUtility.GetCapitalCase(tempName); city.Name = tempName; // *********************************************** // create city // *********************************************** city.AppCreateUserid = systemId; city.AppCreateTimestamp = DateTime.UtcNow; city.AppLastUpdateUserid = systemId; city.AppLastUpdateTimestamp = DateTime.UtcNow; dbContext.Cities.Add(city); } catch (Exception ex) { Debug.WriteLine("***Error*** - City Id: " + oldObject.City_Id); Debug.WriteLine("***Error*** - Service Area Id: " + oldObject.Service_Area_Id); Debug.WriteLine(ex.Message); throw; } }
/// <summary> /// Copy from legacy to new record For the table of HET_City /// </summary> /// <param name="performContext"></param> /// <param name="dbContext"></param> /// <param name="oldObject"></param> /// <param name="city"></param> /// <param name="systemId"></param> private static void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HetsCity oldObject, ref City city, string systemId) { bool isNew = false; if (city == null) { isNew = true; city = new City(); } if (!dbContext.Cities.Any(x => string.Equals(x.Name, oldObject.Name, StringComparison.CurrentCultureIgnoreCase))) { isNew = true; city.Name = oldObject.Name.Trim(); city.Id = dbContext.Cities.Max(x => x.Id) + 1; city.CreateTimestamp = DateTime.UtcNow; city.CreateUserid = systemId; } if (isNew) { dbContext.Cities.Add(city); //Adding the city to the database table of HET_CITY } try { dbContext.SaveChangesForImport(); } catch (Exception e) { performContext.WriteLine("*** ERROR With add or update City ***"); performContext.WriteLine(e.ToString()); } }