예제 #1
0
        /// <summary>
        /// Import Service Areas
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="fileLocation"></param>
        /// <param name="systemId"></param>
        public static void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId)
        {
            // check the start point. If startPoint == sigId then it is already completed
            int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, OldTableProgress, BcBidImport.SigId, NewTable);

            if (startPoint == BcBidImport.SigId)    // this means the import job it has done today is complete for all the records in the xml file.
            {
                performContext.WriteLine("*** Importing " + XmlFileName + " is complete from the former process ***");
                return;
            }

            try
            {
                string rootAttr = "ArrayOf" + OldTable;
                performContext.WriteLine("Processing Service Areas");
                IProgressBar progress = performContext.WriteProgressBar();
                progress.SetValue(0);

                // create serializer and serialize xml file
                XmlSerializer ser = new XmlSerializer(typeof(ImportModels.ServiceArea[]), new XmlRootAttribute(rootAttr));
                ser.UnknownAttribute += ImportUtility.UnknownAttribute;
                ser.UnknownElement   += ImportUtility.UnknownElement;
                MemoryStream memoryStream = ImportUtility.MemoryStreamGenerator(XmlFileName, OldTable, fileLocation, rootAttr);
                ImportModels.ServiceArea[] legacyItems = (ImportModels.ServiceArea[])ser.Deserialize(memoryStream);

                Debug.WriteLine("Importing ServiceArea Data. Total Records: " + legacyItems.Length);

                foreach (ImportModels.ServiceArea item in legacyItems.WithProgress(progress))
                {
                    // see if we have this one already
                    HetImportMap importMap = dbContext.HetImportMap.AsNoTracking()
                                             .FirstOrDefault(x => x.OldTable == OldTable &&
                                                             x.OldKey == item.Service_Area_Id.ToString());

                    // new entry
                    if (importMap == null && item.Service_Area_Cd != "000")
                    {
                        HetServiceArea serviceArea = null;
                        CopyToInstance(dbContext, item, ref serviceArea, systemId);
                        ImportUtility.AddImportMap(dbContext, OldTable, item.Service_Area_Id.ToString(), NewTable, serviceArea.ServiceAreaId);
                    }
                }

                performContext.WriteLine("*** Importing " + XmlFileName + " is Done ***");
                ImportUtility.AddImportMapForProgress(dbContext, OldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, NewTable);
                dbContext.SaveChangesForImport();
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="localArea"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, ImportModels.Area oldObject,
                                           ref HetLocalArea localArea, string systemId)
        {
            try
            {
                if (oldObject.Area_Id <= 0)
                {
                    return;
                }

                string tempLocalArea = ImportUtility.CleanString(oldObject.Area_Desc);
                tempLocalArea = ImportUtility.GetCapitalCase(tempLocalArea);

                localArea = new HetLocalArea
                {
                    LocalAreaId     = oldObject.Area_Id,
                    LocalAreaNumber = oldObject.Area_Id,
                    Name            = tempLocalArea
                };

                // map to the correct service area
                HetServiceArea serviceArea = dbContext.HetServiceArea.AsNoTracking()
                                             .FirstOrDefault(x => x.MinistryServiceAreaId == oldObject.Service_Area_Id);

                if (serviceArea == null)
                {
                    // not mapped correctly
                    return;
                }

                localArea.ServiceAreaId = serviceArea.ServiceAreaId;

                localArea.AppCreateUserid        = systemId;
                localArea.AppCreateTimestamp     = DateTime.UtcNow;
                localArea.AppLastUpdateUserid    = systemId;
                localArea.AppLastUpdateTimestamp = DateTime.UtcNow;

                dbContext.HetLocalArea.Add(localArea);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="serviceArea"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, ImportModels.ServiceArea oldObject,
                                           ref HetServiceArea serviceArea, string systemId)
        {
            try
            {
                if (serviceArea == null)
                {
                    serviceArea = new HetServiceArea();
                }

                if (oldObject.Service_Area_Id <= 0)
                {
                    return;
                }

                serviceArea.ServiceAreaId         = oldObject.Service_Area_Id;
                serviceArea.MinistryServiceAreaId = oldObject.Service_Area_Id;
                serviceArea.Name = oldObject.Service_Area_Desc.Trim();

                // remove " CA" from Service Area Names
                if (serviceArea.Name.EndsWith(" CA"))
                {
                    serviceArea.Name = serviceArea.Name.Replace(" CA", "");
                }

                // service area number
                if (oldObject.Service_Area_Cd != null)
                {
                    serviceArea.AreaNumber = int.Parse(oldObject.Service_Area_Cd);
                }

                // get the district for this service area
                int tempServiceAreaId = GetServiceAreaId(serviceArea.Name);

                if (tempServiceAreaId > 0)
                {
                    HetDistrict district = dbContext.HetDistrict.AsNoTracking()
                                           .FirstOrDefault(x => x.MinistryDistrictId == tempServiceAreaId);

                    if (district != null)
                    {
                        serviceArea.DistrictId = district.DistrictId;
                    }
                }

                if (oldObject.FiscalStart != null)
                {
                    serviceArea.FiscalStartDate = DateTime.ParseExact(oldObject.FiscalStart.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }

                if (oldObject.FiscalEnd != null)
                {
                    serviceArea.FiscalEndDate = DateTime.ParseExact(oldObject.FiscalEnd.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }

                // Address, Phone, etc.
                serviceArea.Address = oldObject.Address.Trim();

                if (serviceArea.Address.Length > 255)
                {
                    serviceArea.Address = serviceArea.Address.Substring(1, 255);
                }

                serviceArea.Phone = oldObject.Phone.Trim();

                if (serviceArea.Phone.Length > 50)
                {
                    serviceArea.Phone = serviceArea.Phone.Substring(1, 50);
                }

                serviceArea.Phone = ImportUtility.FormatPhone(serviceArea.Phone);

                serviceArea.Fax = oldObject.Fax.Trim();

                if (serviceArea.Fax.Length > 50)
                {
                    serviceArea.Fax = serviceArea.Fax.Substring(1, 50);
                }

                serviceArea.Fax = ImportUtility.FormatPhone(serviceArea.Fax);

                serviceArea.SupportingDocuments = oldObject.Sup_Docs.Trim();

                if (serviceArea.SupportingDocuments.Length > 500)
                {
                    serviceArea.SupportingDocuments = serviceArea.SupportingDocuments.Substring(1, 500);
                }

                serviceArea.AppCreateUserid        = systemId;
                serviceArea.AppCreateTimestamp     = DateTime.UtcNow;
                serviceArea.AppLastUpdateUserid    = systemId;
                serviceArea.AppLastUpdateTimestamp = DateTime.UtcNow;

                dbContext.HetServiceArea.Add(serviceArea);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***Error*** - Service Area Id: " + oldObject.Service_Area_Id);
                Debug.WriteLine(ex.Message);
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="user"></param>
        /// <param name="systemId"></param>
        /// <param name="smUserId"></param>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="maxUserIndex"></param>
        private static void CopyToInstance(DbAppContext dbContext, ImportModels.UserHets oldObject,
                                           ref HetUser user, string systemId, string smUserId, string firstName, string lastName,
                                           ref int maxUserIndex)
        {
            try
            {
                // file contains multiple records per user (1 for each district they can access)
                // we are currently importing 1 only -> where Default_Service_Area = Y
                if (oldObject.Default_Service_Area != "Y")
                {
                    return;
                }

                // check if this user already exists in the db
                bool userExists = dbContext.HetUser.Any(x => x.SmUserId == smUserId);

                if (userExists)
                {
                    user = dbContext.HetUser.First(x => x.SmUserId == smUserId);

                    // *******************************************************************
                    // check if this is a different district
                    // *******************************************************************
                    int serviceAreaId;

                    try
                    {
                        serviceAreaId = int.Parse(oldObject.Service_Area_Id);
                    }
                    catch
                    {
                        // not mapped correctly
                        throw new ArgumentException(string.Format("User Error - Invalid Service Area (userId: {0}", user.SmUserId));
                    }

                    HetServiceArea serviceArea = dbContext.HetServiceArea.AsNoTracking()
                                                 .FirstOrDefault(x => x.MinistryServiceAreaId == serviceAreaId);

                    if (serviceArea == null)
                    {
                        // not mapped correctly
                        throw new ArgumentException(string.Format("User Error - Invalid Service Area (userId: {0}", user.SmUserId));
                    }

                    int tempUserId     = user.UserId;
                    int?tempDistrictId = serviceArea.DistrictId;

                    if (tempDistrictId != null)
                    {
                        HetUserDistrict userDistrict = dbContext.HetUserDistrict.AsNoTracking()
                                                       .FirstOrDefault(x => x.User.UserId == tempUserId &&
                                                                       x.District.DistrictId == tempDistrictId);

                        // ***********************************************
                        // create user district record
                        // ***********************************************
                        if (userDistrict == null)
                        {
                            userDistrict = new HetUserDistrict
                            {
                                UserId                 = tempUserId,
                                DistrictId             = tempDistrictId,
                                AppCreateTimestamp     = DateTime.UtcNow,
                                AppCreateUserid        = systemId,
                                AppLastUpdateUserid    = systemId,
                                AppLastUpdateTimestamp = DateTime.UtcNow
                            };

                            dbContext.HetUserDistrict.Add(userDistrict);
                            dbContext.SaveChangesForImport();
                        }
                    }
                }
                else
                {
                    user = new HetUser
                    {
                        UserId   = ++maxUserIndex,
                        Active   = true,
                        SmUserId = smUserId,
                        SmAuthorizationDirectory = "IDIR"
                    };

                    if (!string.IsNullOrEmpty(firstName))
                    {
                        user.GivenName = firstName;
                    }

                    if (!string.IsNullOrEmpty(lastName))
                    {
                        user.Surname = lastName;
                    }

                    // *******************************************************************
                    // create initials
                    // *******************************************************************
                    string temp = "";
                    if (!string.IsNullOrEmpty(lastName) && lastName.Length > 0)
                    {
                        temp = lastName.Substring(0, 1).ToUpper();
                    }

                    if (!string.IsNullOrEmpty(firstName) && firstName.Length > 0)
                    {
                        temp = temp + firstName.Substring(0, 1).ToUpper();
                    }

                    if (!string.IsNullOrEmpty(temp))
                    {
                        user.Initials = temp;
                    }

                    // *******************************************************************
                    // map user to the correct service area
                    // *******************************************************************
                    int serviceAreaId;

                    try
                    {
                        serviceAreaId = int.Parse(oldObject.Service_Area_Id);
                    }
                    catch
                    {
                        // not mapped correctly
                        throw new ArgumentException(string.Format("User Error - Invalid Service Area (userId: {0}", user.SmUserId));
                    }

                    HetServiceArea serviceArea = dbContext.HetServiceArea.AsNoTracking()
                                                 .FirstOrDefault(x => x.MinistryServiceAreaId == serviceAreaId);

                    if (serviceArea == null)
                    {
                        // not mapped correctly
                        throw new ArgumentException(string.Format("User Error - Invalid Service Area (userId: {0}", user.SmUserId));
                    }

                    user.DistrictId = serviceArea.DistrictId;

                    // *******************************************************************
                    // set the user's role
                    // ** all new users will be added with basic access only
                    // *******************************************************************
                    HetUserRole userRole = new HetUserRole();

                    HetRole role = dbContext.HetRole.FirstOrDefault(x => x.Name == "HETS District User");

                    int roleId = -1;

                    if (role != null)
                    {
                        roleId = role.RoleId;
                    }

                    // ***********************************************
                    // create user
                    // ***********************************************
                    user.AppCreateTimestamp     = DateTime.UtcNow;
                    user.AppCreateUserid        = systemId;
                    user.AppLastUpdateUserid    = systemId;
                    user.AppLastUpdateTimestamp = DateTime.UtcNow;

                    userRole.Role          = dbContext.HetRole.First(x => x.RoleId == roleId);
                    userRole.EffectiveDate = DateTime.UtcNow.AddDays(-1);

                    userRole.AppCreateTimestamp     = DateTime.UtcNow;
                    userRole.AppCreateUserid        = systemId;
                    userRole.AppLastUpdateUserid    = systemId;
                    userRole.AppLastUpdateTimestamp = DateTime.UtcNow;

                    user.HetUserRole = new List <HetUserRole> {
                        userRole
                    };
                    dbContext.HetUser.Add(user);
                    dbContext.SaveChangesForImport();

                    // ***********************************************
                    // create user district record
                    // ***********************************************
                    HetUserDistrict userDistrict = new HetUserDistrict
                    {
                        UserId                 = user.UserId,
                        DistrictId             = user.DistrictId,
                        IsPrimary              = true,
                        AppCreateTimestamp     = DateTime.UtcNow,
                        AppCreateUserid        = systemId,
                        AppLastUpdateUserid    = systemId,
                        AppLastUpdateTimestamp = DateTime.UtcNow
                    };

                    dbContext.HetUserDistrict.Add(userDistrict);
                    dbContext.SaveChangesForImport();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***Error*** - Employee Id: " + oldObject.Popt_Id);
                Debug.WriteLine("***Error*** - Master User Index: " + maxUserIndex);
                Debug.WriteLine(ex.Message);
                throw;
            }
        }
        /// <summary>
        /// Copy xml item to instance (table entries)
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="equipType"></param>
        /// <param name="systemId"></param>
        /// <param name="maxEquipTypeIndex"></param>
        private static void CopyToInstance(DbAppContext dbContext, ImportModels.EquipType oldObject,
                                           ref HetDistrictEquipmentType equipType, string systemId, ref int maxEquipTypeIndex)
        {
            try
            {
                if (equipType != null)
                {
                    return;
                }

                // ***********************************************
                // get the equipment type
                // ***********************************************
                float?tempBlueBookRate = ImportUtility.GetFloatValue(oldObject.Equip_Rental_Rate_No);

                if (tempBlueBookRate == null)
                {
                    return;
                }

                // ***********************************************
                // get the parent equipment type
                // ***********************************************
                HetEquipmentType type = dbContext.HetEquipmentType.FirstOrDefault(x => x.BlueBookSection == tempBlueBookRate);

                // if it's not found - try to round up to the "parent" blue book section
                if (type == null)
                {
                    int tempIntBlueBookRate = Convert.ToInt32(tempBlueBookRate);
                    type = dbContext.HetEquipmentType.FirstOrDefault(x => x.BlueBookSection == tempIntBlueBookRate);
                }

                // finally - if that's not found - map to 0 (MISCELLANEOUS)
                if (type == null)
                {
                    int tempIntBlueBookRate = 0;
                    type = dbContext.HetEquipmentType.FirstOrDefault(x => x.BlueBookSection == tempIntBlueBookRate);
                }

                if (type == null)
                {
                    throw new ArgumentException(
                              string.Format("Cannot find Equipment Type (Blue Book Rate Number: {0} | Equipment Type Id: {1})",
                                            tempBlueBookRate.ToString(), oldObject.Equip_Type_Id));
                }

                // ***********************************************
                // get the description
                // ***********************************************
                string tempDistrictDescriptionOnly = ImportUtility.CleanString(oldObject.Equip_Type_Desc);
                tempDistrictDescriptionOnly = ImportUtility.GetCapitalCase(tempDistrictDescriptionOnly);

                // cleaning up a few data errors from BC Bid
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("  ", " ");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" Lrg", "Lgr");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" LoadLgr", " Load Lgr");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("23000 - 37999", "23000-37999");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator- Class 1", "Excavator-Class 1");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" 3-4(19.05-23.13)Tonnes", " 3-4 (19.05-23.13)Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" 3 - 4 (19.05-23.13)Tonnes", " 3-4 (19.05-23.13)Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" 5(23.13-26.76)Tonnes", " 5 (23.13-26.76)Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" 6(26.76-30.84)Tonnes", " 6 (26.76-30.84)Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" 7(30.84-39.92)Tonnes", " 7 (30.84-39.92)Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator-Class 8 - 12", "Excavator-Class 8-12");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(")Tonnes", ") Tonnes");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("(Trailer/Skidmou", "(Trailer/Skidmou)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(" Lgr", "Large");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Compressors", "Compressor");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Bulldozers-Mini", "Bulldozer Mini");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Curbing Machines", "Curbing Machine");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Drilling, Specialized Equipment", "Specialized Drilling Equipment");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Geotch. Drilling Companie", "Geotch. Drilling Company");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavators", "Excavator");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavatr", "Excavator");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excvtr", "Excavator");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Attachements", "Attachments");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 2 To 41,000 Lbs", "Class 2 To 41,999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Heavy Excavator Class 5 To 58,999", "Heavy Excavator Class 5 To 58,999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Heavy Excavator Class 6 To 67,999", "Heavy Excavator Class 6 To 67,999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Heavy Excavator Class 7 To 87.999", "Heavy Excavator Class 7 To 87.999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Heavy Excavator Class 9 To 152,999 Lbs", "Heavy Excavator Class Class 9-12 To 152,999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 1 (Under 32000 Lbs)", "Excav Class 1 (Under 32000 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 2 (32000 - 41999 Lbs)", "Excav Class 2 (32000-41999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 3 (42000 - 44999 Lbs)", "Excav Class 3 (42000-44999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 4 (45000 - 50999 Lbs)", "Excav Class 4 (45000-50999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 5 (51000 - 58999 Lbs)", "Excav Class 5 (51000-58999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 6 (59000 - 67999 Lbs)", "Excav Class 6 (59000-67999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 8 (88000 - 95999 Lbs)", "Excav Class 8 (88000-95999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 9 (96000 - 102999 Lbs)", "Excav Class 9 (96000-102999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 10 (103000 - 118999 Lbs)", "Excav Class 10 (103000-118999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excav Class 11 (119000 - 151999 Lbs)", "Excav Class 11 (119000-151999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator-Class 8-12(39.92-68.95+)", "Excavator-Class 8-12 (39.92-68.95+)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace(") Lbs", " Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Lbs Lbs", "Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Lbs.", "Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Lb", "Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Lbss", "Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("999Lbs", "999 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("000Lbs+", "000 Lbs+");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("000 Lbs +", "000 Lbs+");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("000+ - 152,000Lbs", "000-152,000 Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tract.1", "Tract. 1");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tract.2", "Tract. 2");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class Class", "Class");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Graders 130 - 144 Fwhp", "Graders 130-144 Fwhp");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Graders Under 100 - 129 Fwhp", "Graders Under 100-129 Fwhp");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Craw.64-90,999Lbs", "Craw 64-90,999Lbs");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator Mini-", "Excavator Mini -");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator Mini -2", "Excavator Mini - 2");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator Mini 2", "Excavator Mini - 2");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Flat Decks", "Flat Deck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Misc. Equipment", "Misc Equipment");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Misc. Equip", "Miscellaneous");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Pipe Crews", "Pipe Crew");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Pipecrew", "Pipe Crew");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roll.TandemLarge.", "Roll. Tandem Large");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roll. TandemLarge", "Roll. Tandem Large");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roll.Tandem Med.", "Roll. Tandem Med");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Scraper - Two Engine -", "Scraper - Two Engines -");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("14.2 Scrapers", "14.2 Scraper");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Skidders", "Skidder");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Selfprop Scrapr", "Self Prop Scrapr");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Bellydump", "Belly Dump");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Dump Combo Pup", "Dump Combo (Pup)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tandem Dump Trk", "Tandem Dump Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tandem Dump Trks", "Tandem Dump Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tandem Dump Truc", "Tandem Dump Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tandem Dump Truckk", "Tandem Dump Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tractor/Trailers", "Tractor Trailers");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Truck - Tractor Trucks", "Truck - Tractor Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Loaders-Rubber Tired", "Loaders - Rubber Tired");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tractor-Crawler-Class ", "Tractor - Crawler - Class ");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Heavy Hydraulic Excav Class 11 (119000 - 151999 Lbs)", "Heavy Hydraulic Excav Class 11 (119000-151999 Lbs)");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 1-3 Under", "Class 1-3 - Under");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 4-5 2", "Class 4-5 - 2");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 6-7 3", "Class 6-7 - 3");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 8-9 4", "Class 8-9 - 4");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 10-11 5", "Class 10-11 - 5");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 12-16 6", "Class 12-16 - 6");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Tractors-Rubber Tired", "Tractors - Rubber Tired");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("(Rubber Tired)6.", "(Rubber Tired) 6");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Rubber Tired-Class ", "Rubber Tired - Class ");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("20 - 59.9 Fhwp", "20-59.9 Fhwp");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("20 - 150+ Fhwp", "20-150+ Fhwp");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 6-11 60-119.9 Fwhp", "Class 6-11 - 60-119.9 Fwhp");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Water Trucks", "Water Truck");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Welding Outfit/Truck Mounted", "Welding Outfit-Truck Mounted");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator-Wheeled-Class", "Excavator-Wheeled - Class");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 1-2(", "Class 1-2 - (");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Class 3(", "Class 3 - (");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Backhoe Sm.-40", "Backhoe Sm. -40");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Water Truck -Tandem", "Water Truck - Tandem");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer-Class ", "Roller/Packer - Class ");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer - Class 7 - 11", "Roller/Packer - Class 7-11");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer - Class 5 8", "Roller/Packer - Class 5 - 8");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer - Class 2-4", "Roller/Packer - Class 2 - 4");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer - Class 7-11", "Roller/Packer - Class 7 - 11");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Sp,Vib,Rubber", "Sp, Vib, Rubber");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Roller/Packer 10-15.9T, ", "Roller/Packer 10-15.9T ");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator-Class", "Excavator - Class");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator - Class 3 6", "Excavator - Class 3 - 6");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator - Class 2 3", "Excavator - Class 2 - 3");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Excavator - Class 5 13", "Excavator - Class 5 - 13");
                tempDistrictDescriptionOnly = tempDistrictDescriptionOnly.Replace("Graders-Class", "Graders - Class");

                // get the abbreviation portion
                string tempAbbrev = ImportUtility.CleanString(oldObject.Equip_Type_Cd).ToUpper();

                // cleaning up a few data errors from BC Bid
                tempAbbrev = tempAbbrev.Replace("BUCTRK", "BUCKET");
                tempAbbrev = tempAbbrev.Replace("DUMP 1", "DUMP1");
                tempAbbrev = tempAbbrev.Replace("DUMP 2", "DUMP2");
                tempAbbrev = tempAbbrev.Replace("MIS", "MISC");
                tempAbbrev = tempAbbrev.Replace("MISCC", "MISC");
                tempAbbrev = tempAbbrev.Replace("HEL", "HELICOP");
                tempAbbrev = tempAbbrev.Replace("SCRNGEQ", "SCRPLA");
                tempAbbrev = tempAbbrev.Replace("SECT. ", "SECT.");
                tempAbbrev = tempAbbrev.Replace("SKI", "SKID");
                tempAbbrev = tempAbbrev.Replace("SKIDD", "SKID");
                tempAbbrev = tempAbbrev.Replace("SSM", "SSS");
                tempAbbrev = tempAbbrev.Replace("SSP", "SSS");
                tempAbbrev = tempAbbrev.Replace("TFC", "TFD");
                tempAbbrev = tempAbbrev.Replace("TRUCKS/", "TRUCKS");
                tempAbbrev = tempAbbrev.Replace("TDB", "TBD");

                string tempDistrictDescriptionFull = string.Format("{0} - {1}", tempAbbrev, tempDistrictDescriptionOnly);

                // add new district equipment type
                int tempId = type.EquipmentTypeId;

                equipType = new HetDistrictEquipmentType
                {
                    DistrictEquipmentTypeId = ++maxEquipTypeIndex,
                    EquipmentTypeId         = tempId,
                    DistrictEquipmentName   = tempDistrictDescriptionFull
                };

                // ***********************************************
                // set the district
                // ***********************************************
                HetServiceArea serviceArea = dbContext.HetServiceArea.AsNoTracking()
                                             .Include(x => x.District)
                                             .FirstOrDefault(x => x.MinistryServiceAreaId == oldObject.Service_Area_Id);

                if (serviceArea == null)
                {
                    throw new ArgumentException(
                              string.Format("Cannot find Service Area (Service Area Id: {0} | Equipment Type Id: {1})",
                                            oldObject.Service_Area_Id, oldObject.Equip_Type_Id));
                }

                int districtId = serviceArea.District.DistrictId;
                equipType.DistrictId = districtId;

                // ***********************************************
                // check that we don't have this equipment type
                // already (from another service area - but same district)
                // ***********************************************
                HetDistrictEquipmentType existingEquipmentType = dbContext.HetDistrictEquipmentType.AsNoTracking()
                                                                 .Include(x => x.District)
                                                                 .FirstOrDefault(x => x.DistrictEquipmentName == tempDistrictDescriptionFull &&
                                                                                 x.District.DistrictId == districtId);

                if (existingEquipmentType != null)
                {
                    equipType.DistrictEquipmentTypeId = existingEquipmentType.DistrictEquipmentTypeId;
                    return; // not adding a duplicate
                }

                // ***********************************************
                // save district equipment type record
                // ***********************************************
                equipType.AppCreateUserid        = systemId;
                equipType.AppCreateTimestamp     = DateTime.UtcNow;
                equipType.AppLastUpdateUserid    = systemId;
                equipType.AppLastUpdateTimestamp = DateTime.UtcNow;

                dbContext.HetDistrictEquipmentType.Add(equipType);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***Error*** - (Old) Equipment Code: " + oldObject.Equip_Type_Cd);
                Debug.WriteLine("***Error*** - Master District Equipment Index: " + maxEquipTypeIndex);
                Debug.WriteLine(ex.Message);
                throw;
            }
        }
예제 #6
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="project"></param>
        /// <param name="systemId"></param>
        /// <param name="maxProjectIndex"></param>
        private static void CopyToInstance(DbAppContext dbContext, Project oldObject,
                                           ref HetProject project, string systemId, ref int maxProjectIndex)
        {
            try
            {
                if (project != null)
                {
                    return;
                }

                project = new HetProject {
                    ProjectId = ++maxProjectIndex
                };

                // ***********************************************
                // set project properties
                // ***********************************************
                string tempProjectNumber = ImportUtility.CleanString(oldObject.Project_Num).ToUpper();
                if (!string.IsNullOrEmpty(tempProjectNumber))
                {
                    project.ProvincialProjectNumber = tempProjectNumber;
                }

                // project name
                string tempName = ImportUtility.CleanString(oldObject.Job_Desc1).ToUpper();
                if (!string.IsNullOrEmpty(tempName))
                {
                    project.Name = ImportUtility.GetCapitalCase(tempName);
                }

                // project information
                string tempInformation = ImportUtility.CleanString(oldObject.Job_Desc2);
                if (!string.IsNullOrEmpty(tempInformation))
                {
                    tempInformation     = ImportUtility.GetUppercaseFirst(tempInformation);
                    project.Information = tempInformation;
                }

                // ***********************************************
                // set service area for the project
                // ***********************************************
                HetServiceArea serviceArea = dbContext.HetServiceArea.AsNoTracking()
                                             .Include(x => x.District)
                                             .FirstOrDefault(x => x.MinistryServiceAreaId == oldObject.Service_Area_Id);

                if (serviceArea == null)
                {
                    throw new DataException(string.Format("Service Area cannot be null (ProjectIndex: {0}", maxProjectIndex));
                }

                int tempDistrictId = serviceArea.District.DistrictId;

                project.DistrictId = tempDistrictId;

                // ***********************************************
                // check that we don't have this equipment type
                // already (from another service area - but same district)
                // ***********************************************
                HetProject existingProject = dbContext.HetProject.AsNoTracking()
                                             .Include(x => x.ProjectStatusType)
                                             .Include(x => x.District)
                                             .FirstOrDefault(x => x.Name == tempName &&
                                                             x.District.DistrictId == tempDistrictId);

                if (existingProject != null)
                {
                    project.ProjectId = existingProject.ProjectId;
                    return; // not adding a duplicate
                }

                // ***********************************************
                // default the project to Active
                // ***********************************************
                int?statusId = StatusHelper.GetStatusId(HetProject.StatusActive, "projectStatus", dbContext);

                if (statusId == null)
                {
                    throw new DataException(string.Format("Status Id cannot be null (ProjectIndex: {0}", maxProjectIndex));
                }

                project.ProjectStatusTypeId = (int)statusId;

                // ***********************************************
                // create project
                // ***********************************************
                project.AppCreateUserid        = systemId;
                project.AppCreateTimestamp     = DateTime.UtcNow;
                project.AppLastUpdateUserid    = systemId;
                project.AppLastUpdateTimestamp = DateTime.UtcNow;

                dbContext.HetProject.Add(project);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***Error*** - Project Name: " + oldObject.Job_Desc1);
                Debug.WriteLine("***Error*** - Master project Index: " + maxProjectIndex);
                Debug.WriteLine(ex.Message);
                throw;
            }
        }