Esempio n. 1
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, EquipType oldObject, ref EquipmentType instance, string systemId)
        {
            if (oldObject.Equip_Type_Id <= 0)
            {
                return;
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new EquipmentType
                {
                    Id          = oldObject.Equip_Type_Id,
                    IsDumpTruck = false
                };

                try
                {
                    instance.ExtendHours  = float.Parse(oldObject.Extend_Hours.Trim());
                    instance.MaximumHours = float.Parse(oldObject.Max_Hours.Trim());
                    instance.MaxHoursSub  = float.Parse(oldObject.Max_Hours_Sub.Trim());
                }
                catch
                {
                    // do nothing
                }

                try
                {
                    instance.Name = oldObject.Equip_Type_Cd.Trim();
                }
                catch
                {
                    // do nothing
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.EquipmentTypes.Add(instance);
            }
            else
            {
                instance = dbContext.EquipmentTypes.First(x => x.Id == oldObject.Equip_Type_Id);
                instance.LastUpdateUserid = modifiedBy.SmUserId;

                try
                {
                    instance.LastUpdateTimestamp = DateTime.ParseExact(oldObject.Modified_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch
                {
                    // do nothing
                }

                dbContext.EquipmentTypes.Update(instance);
            }
        }
Esempio n. 2
0
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipType oldObject, ref Models.EquipmentType instance, string systemId)
        {
            bool isNew = false;

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

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                isNew                = true;
                instance             = new Models.EquipmentType();
                instance.Id          = oldObject.Equip_Type_Id;
                instance.IsDumpTruck = false;   // Where this is coming from?   !!!!!!
                try
                {
                    instance.ExtendHours  = float.Parse(oldObject.Extend_Hours.Trim());
                    instance.MaximumHours = float.Parse(oldObject.Max_Hours.Trim());
                    instance.MaxHoursSub  = float.Parse(oldObject.Max_Hours_Sub.Trim());
                }
                catch
                {
                }
                try
                {
                    instance.Name = oldObject.Equip_Type_Cd.Trim();
                }
                catch
                {
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.EquipmentTypes.Add(instance);
            }
            else
            {
                instance = dbContext.EquipmentTypes
                           .First(x => x.Id == oldObject.Equip_Type_Id);
                instance.LastUpdateUserid = modifiedBy.SmUserId;
                try
                {
                    instance.LastUpdateTimestamp = DateTime.ParseExact(oldObject.Modified_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch
                {
                }
                dbContext.EquipmentTypes.Update(instance);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Copy Block item of LocalAreaRotationList item
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, Block oldObject, ref LocalAreaRotationList instance, string systemId)
        {
            if (oldObject.Area_Id <= 0)
            {
                return;
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            int equipmentTypeId = oldObject.Equip_Type_Id ?? 0;
            int blockNum        = Convert.ToInt32(float.Parse(oldObject.Block_Num == null ? "0.0" : oldObject.Block_Num));

            if (instance == null)
            {
                instance = new LocalAreaRotationList();

                DistrictEquipmentType disEquipType = dbContext.DistrictEquipmentTypes.FirstOrDefault(x => x.Id == equipmentTypeId);
                if (disEquipType != null)
                {
                    instance.DistrictEquipmentType   = disEquipType;
                    instance.DistrictEquipmentTypeId = disEquipType.Id;
                }

                // extract AskNextBlock*Id which is the secondary key of Equip.Id
                int equipId = oldObject.Last_Hired_Equip_Id ?? 0;

                if (dbContext.Equipments.Any(x => x.Id == equipId))
                {
                    switch (blockNum)
                    {
                    case 1:
                        instance.AskNextBlockOpenId = equipId;
                        break;

                    case 2:
                        instance.AskNextBlock1Id = equipId;
                        break;

                    case 3:
                        instance.AskNextBlock2Id = equipId;
                        break;
                    }
                }

                instance.CreateUserid = createdBy.SmUserId;

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

                dbContext.LocalAreaRotationLists.Add(instance);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Copy xml item to instance (table entries)
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipType oldObject, ref Models.DistrictEquipmentType instance, string systemId)
        {
            bool isNew = false;

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

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                isNew       = true;
                instance    = new Models.DistrictEquipmentType();
                instance.Id = oldObject.Equip_Type_Id;



                try  //Combining <Equip_Type_Cd> and < Equip_Type_Desc> together
                {
                    instance.DistrictEquipmentName = oldObject.Equip_Type_Cd.Length >= 10 ? oldObject.Equip_Type_Cd.Substring(0, 10) : oldObject.Equip_Type_Cd
                                                     + "-" + (oldObject.Equip_Type_Desc.Length >= 210 ? oldObject.Equip_Type_Desc.Substring(0, 210) : oldObject.Equip_Type_Desc);
                    // instance.DistrictEquipmentName = oldObject.ToDelimString(" | ");
                }
                catch
                {
                }

                ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id);
                if (serviceArea != null)
                {
                    int      districtId = serviceArea.DistrictId ?? 0;
                    District dis        = dbContext.Districts.FirstOrDefault(x => x.RegionId == districtId);
                    instance.DistrictId = districtId;
                    instance.District   = dis;
                }

                //    instance.EquipmentType =
                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.DistrictEquipmentTypes.Add(instance);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Copy xml item to instance (table entries)
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, EquipType oldObject, ref DistrictEquipmentType instance, string systemId)
        {
            if (oldObject.Equip_Type_Id <= 0)
            {
                return;
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new DistrictEquipmentType {
                    Id = oldObject.Equip_Type_Id
                };

                try
                {
                    instance.DistrictEquipmentName = oldObject.Equip_Type_Cd.Length >= 10 ?
                                                     oldObject.Equip_Type_Cd.Substring(0, 10) :
                                                     oldObject.Equip_Type_Cd
                                                     + "-" + (oldObject.Equip_Type_Desc.Length >= 210 ?
                                                              oldObject.Equip_Type_Desc.Substring(0, 210) :
                                                              oldObject.Equip_Type_Desc);
                }
                catch
                {
                    // do nothing
                }

                ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id);

                if (serviceArea != null)
                {
                    int      districtId = serviceArea.DistrictId ?? 0;
                    District dis        = dbContext.Districts.FirstOrDefault(x => x.RegionId == districtId);
                    instance.DistrictId = districtId;
                    instance.District   = dis;
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.DistrictEquipmentTypes.Add(instance);
            }
        }
Esempio n. 6
0
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipAttach oldObject, ref Models.EquipmentAttachment instance,
                                           List <Models.Equipment> equips, string systemId)
        {
            if (oldObject.Equip_Id <= 0)
            {
                return;
            }

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            //  Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId, true);
            Models.User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new Models.EquipmentAttachment();
                int equipId = oldObject.Equip_Id ?? -1;

                Models.Equipment equipment = equips.FirstOrDefault(x => x.Id == equipId);
                if (equipment != null)
                {
                    instance.Equipment   = equipment;
                    instance.EquipmentId = equipment.Id;
                }

                instance.Description = oldObject.Attach_Desc == null ? "" : oldObject.Attach_Desc;
                instance.TypeName    = (oldObject.Attach_Seq_Num ?? -1).ToString();
                if (oldObject.Created_Dt != null && oldObject.Created_Dt.Trim().Length >= 10)
                {
                    instance.CreateTimestamp =
                        DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }

                instance.CreateUserid = createdBy.SmUserId;

                dbContext.EquipmentAttachments.Add(instance);
            }
            else
            {
                instance = dbContext.EquipmentAttachments
                           .First(x => x.EquipmentId == oldObject.Equip_Id && x.TypeName == (oldObject.Attach_Seq_Num ?? -2).ToString());
                instance.LastUpdateUserid    = systemId; // modifiedBy.SmUserId;
                instance.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.EquipmentAttachments.Update(instance);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Copy xml item to instance (table entries)
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.Rotation_Doc oldObject, ref Models.Note instance,
                                           List <Models.Equipment> equips, List <Models.Project> projs, string systemId)
        {
            bool isNew = false;

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                isNew    = true;
                instance = new Models.Note();

                Models.Project   proj  = projs.FirstOrDefault(x => x.Id == oldObject.Project_Id);
                Models.Equipment equip = equips.FirstOrDefault(x => x.Id == oldObject.Equip_Id);
                if (equip != null)
                {
                    if (equip.Notes == null)
                    {
                        equip.Notes = new List <Note>();
                    }


                    Models.Note note = new Note();
                    note.Text = new string(oldObject.Reason.Take(2048).ToArray());
                    note.IsNoLongerRelevant = true;
                    if (proj != null)
                    { // The current model does not allow Project Id to be added to thge Note. while Note model should have Project ID
                      // note. = oldObject.Project_Id;
                    }
                    equip.Notes.Add(note);
                    dbContext.Equipments.Update(equip);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, DumpTruck oldObject, ref Models.DumpTruck instance, string systemId)
        {
            if (oldObject.Equip_Id <= 0)
            {
                return;
            }

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, "", systemId);

            if (instance == null)
            {
                instance = new Models.DumpTruck {
                    Id = oldObject.Equip_Id
                };

                if (oldObject.Single_Axle != null)
                {
                    instance.IsSingleAxle = (oldObject.Single_Axle.Trim() == "Y");
                }

                if (oldObject.Tandem_Axle != null)
                {
                    instance.IsTandemAxle = (oldObject.Tandem_Axle.Trim() == "Y");
                }

                if (oldObject.Tridem != null)
                {
                    instance.IsTridem = (oldObject.Tridem.Trim() == "Y");
                }

                if (oldObject.PUP != null)
                {
                    instance.HasPUP = (oldObject.PUP.Trim() == "Y");
                }

                if (oldObject.Belly_Dump != null)
                {
                    instance.HasBellyDump = (oldObject.Belly_Dump.Trim() == "Y");
                }

                if (oldObject.Rock_Box != null)
                {
                    instance.HasRockBox = (oldObject.Rock_Box.Trim() == "Y");
                }

                if (oldObject.Hilift_Gate != null)
                {
                    instance.HasHiliftGate = (oldObject.Hilift_Gate.Trim() == "Y");
                }

                if (oldObject.Water_Truck != null)
                {
                    instance.IsWaterTruck = (oldObject.Water_Truck.Trim() == "Y");
                }

                if (oldObject.Seal_Coat_Hitch != null)
                {
                    instance.HasSealcoatHitch = (oldObject.Seal_Coat_Hitch.Trim() == "Y");
                }

                if (oldObject.Rear_Axle_Spacing != null)
                {
                    instance.RearAxleSpacing = oldObject.Rear_Axle_Spacing;
                }

                if (oldObject.Front_Tire_Size != null)
                {
                    instance.FrontTireSize = oldObject.Front_Tire_Size;
                }

                if (oldObject.Front_Tire_UOM != null)
                {
                    instance.FrontTireUOM = oldObject.Front_Tire_UOM;
                }

                if (oldObject.Front_Axle_Capacity != null)
                {
                    instance.FrontAxleCapacity = oldObject.Front_Axle_Capacity;
                }

                if (oldObject.Rear_Axle_Capacity != null)
                {
                    instance.RearAxleCapacity = oldObject.Rear_Axle_Capacity;
                }

                if (oldObject.Legal_Load != null)
                {
                    instance.LegalLoad = oldObject.Legal_Load;
                }

                if (oldObject.Legal_Capacity != null)
                {
                    instance.LegalCapacity = oldObject.Legal_Capacity;
                }

                if (oldObject.Legal_PUP_Tare_Weight != null)
                {
                    instance.LegalPUPTareWeight = oldObject.Legal_PUP_Tare_Weight;
                }

                if (oldObject.Licenced_GVW != null)
                {
                    instance.LicencedGVW = oldObject.Licenced_GVW;
                }

                if (oldObject.Licenced_GVW_UOM != null)
                {
                    instance.LicencedGVWUOM = oldObject.Licenced_GVW_UOM;
                }

                if (oldObject.Licenced_Tare_Weight != null)
                {
                    instance.LicencedTareWeight = oldObject.Licenced_Tare_Weight;
                }

                if (oldObject.Licenced_PUP_Tare_Weight != null)
                {
                    instance.LicencedPUPTareWeight = oldObject.Licenced_PUP_Tare_Weight;
                }

                if (oldObject.Licenced_Load != null)
                {
                    instance.LicencedLoad = oldObject.Licenced_Load;
                }

                if (oldObject.Licenced_Capacity != null)
                {
                    instance.LicencedCapacity = oldObject.Licenced_Capacity;
                }

                if (oldObject.Box_Length != null)
                {
                    instance.BoxLength = oldObject.Box_Length;
                }

                if (oldObject.Box_Width != null)
                {
                    instance.BoxWidth = oldObject.Box_Width;
                }

                if (oldObject.Box_Height != null)
                {
                    instance.BoxHeight = oldObject.Box_Height;
                }

                if (oldObject.Box_Capacity != null)
                {
                    instance.BoxCapacity = oldObject.Box_Capacity;
                }

                if (oldObject.Trailer_Box_Length != null)
                {
                    instance.TrailerBoxLength = oldObject.Trailer_Box_Length;
                }

                if (oldObject.Trailer_Box_Width != null)
                {
                    instance.TrailerBoxWidth = oldObject.Trailer_Box_Width;
                }

                if (oldObject.Trailer_Box_Height != null)
                {
                    instance.TrailerBoxHeight = oldObject.Trailer_Box_Height;
                }

                if (oldObject.Trailer_Box_Capacity != null)
                {
                    instance.TrailerBoxCapacity = oldObject.Trailer_Box_Capacity;
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.DumpTrucks.Add(instance);
            }
            else
            {
                instance = dbContext.DumpTrucks.First(x => x.Id == oldObject.Equip_Id);
                instance.LastUpdateUserid    = modifiedBy.SmUserId;
                instance.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.DumpTrucks.Update(instance);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// /// <summary>
        /// Copy xml item to instance (table entries)
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        /// <param name="equip_Rental_rate_No"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        static private string CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipType oldObject,
                                             ref Models.DistrictEquipmentType instance, string systemId, float equip_Rental_rate_No, string description)
        {
            string serviceAreaName = "";
            bool   isNew           = false;

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

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                isNew       = true;
                instance    = new Models.DistrictEquipmentType();
                instance.Id = oldObject.Equip_Type_Id;
                string typeCode = "";
                try
                {
                    typeCode = oldObject.Equip_Type_Cd.Length >= 20 ? oldObject.Equip_Type_Cd.Substring(0, 20) : oldObject.Equip_Type_Cd;
                }
                catch (Exception e)
                {
                    string ll = e.ToString();
                }

                ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id);
                if (serviceArea != null)
                {
                    serviceAreaName = serviceArea.Name;
                    instance.DistrictEquipmentName = typeCode;

                    int      districtId = serviceArea.DistrictId ?? 0;
                    District dis        = dbContext.Districts.FirstOrDefault(x => x.RegionId == districtId);
                    instance.DistrictId = districtId;
                    instance.District   = dis;
                }

                //    instance.EquipmentType =
                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                Models.DistrictEquipmentType dt = new DistrictEquipmentType();
                if (oldObject.Equip_Type_Cd != null)
                {
                    EquipmentType eType = dbContext.EquipmentTypes.FirstOrDefault(x => (Math.Abs((x.BlueBookSection ?? 0.1) - equip_Rental_rate_No)) <= errowAllowed);
                    if (eType == null)
                    {
                        eType = dbContext.EquipmentTypes.FirstOrDefault(x => (Math.Abs((x.BlueBookSection ?? 0.1) - defaultBlueBoxSection)) <= errowAllowed);
                    }
                    //else    //Just in case we need to update the table of EQUIPMENT_TYPE
                    //{
                    //    if (eType.BlueBookRateNumber == 0.0)  // Update etype with BLUE_BOOK_RATE_NUMBER, MAXIMUN
                    //    {
                    //        try
                    //        {
                    //            eType.MaximumHours = (float)Decimal.Parse(oldObject.Max_Hours, System.Globalization.NumberStyles.Any);
                    //        }
                    //        catch (Exception e)
                    //        {
                    //            string ii = e.ToString();
                    //        }
                    //        try
                    //        {
                    //            eType.MaxHoursSub = (float)Decimal.Parse(oldObject.Max_Hours_Sub, System.Globalization.NumberStyles.Any);
                    //        }
                    //        catch (Exception e)
                    //        {
                    //            string ii = e.ToString();
                    //        }
                    //        try
                    //        {
                    //            eType.ExtendHours = (float)Decimal.Parse(oldObject.Extend_Hours, System.Globalization.NumberStyles.Any);
                    //        }
                    //        catch (Exception e)
                    //        {
                    //            string ii = e.ToString();
                    //        }
                    //        eType.LastUpdateTimestamp = DateTime.ParseExact(oldObject.Created_Dt == null ? "1900-01-01" : oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                    //        eType.LastUpdateUserid = createdBy.SmUserId;
                    //        //Update some content of the Equipment Type
                    //        dbContext.EquipmentTypes.Update(eType);
                    //    }
                    //}
                    instance.EquipmentTypeId = eType.Id;
                }
            }
            return(serviceAreaName);
        }
Esempio n. 10
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="owner"></param>
        /// <param name="systemId"></param>
        /// <param name="maxOwnerIndex"></param>
        /// <param name="maxContactIndex"></param>
        private static void CopyToInstance(DbAppContext dbContext, ImportModels.Owner oldObject, ref Owner owner,
                                           string systemId, ref int maxOwnerIndex, ref int maxContactIndex)
        {
            bool isNew = false;

            if (owner == null)
            {
                isNew = true;
                owner = new Owner {
                    Id = ++maxOwnerIndex
                };
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            try
            {
                owner.IsMaintenanceContractor = (oldObject.Maintenance_Contractor.Trim() == "Y");
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.LocalArea = dbContext.LocalAreas.FirstOrDefault(x => x.Id == oldObject.Area_Id);
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.CGLEndDate =
                    DateTime.ParseExact(oldObject.CGL_End_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.WorkSafeBCExpiryDate =
                    DateTime.ParseExact(oldObject.WCB_Expiry_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.WorkSafeBCPolicyNumber = oldObject.WCB_Num.Trim();
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.OrganizationName = oldObject.CGL_Company.Trim();
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.ArchiveCode = oldObject.Archive_Cd;
            }
            catch
            {
                // do nothing
            }

            try
            {
                owner.Status = oldObject.Status_Cd.Trim();
            }
            catch
            {
                // do nothing
            }

            Contact con = dbContext.Contacts.FirstOrDefault(x => x.GivenName.ToUpper() == oldObject.Owner_First_Name.Trim().ToUpper() && x.Surname.ToUpper() == oldObject.Owner_Last_Name.Trim().ToUpper());

            if (con == null)
            {
                con = new Contact(++maxContactIndex);

                try
                {
                    con.Surname   = oldObject.Owner_Last_Name.Trim();
                    con.GivenName = oldObject.Owner_First_Name.Trim();
                    owner.OwnerEquipmentCodePrefix = con.GivenName.Substring(0, 1) + con.Surname.Substring(0, 1);
                }
                catch
                {
                    // do nothing
                }

                con.FaxPhoneNumber = "";
                con.Province       = "BC";

                try
                {
                    con.Notes = new string(oldObject.Comment.Take(511).ToArray());
                }
                catch
                {
                    // do nothing
                }

                dbContext.Contacts.Add(con);
            }

            // TODO finish mapping here
            if (isNew)
            {
                owner.CreateUserid = createdBy.SmUserId;

                try
                {
                    owner.CreateTimestamp =
                        DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch
                {
                    owner.CreateTimestamp = DateTime.UtcNow;
                }

                con.CreateUserid     = createdBy.SmUserId;
                owner.PrimaryContact = con;
                dbContext.Owners.Add(owner);
            }
            else  // the owner existed in the database
            {
                try
                {
                    owner.LastUpdateUserid    = systemId;
                    owner.LastUpdateTimestamp = DateTime.UtcNow;
                    con.LastUpdateTimestamp   = DateTime.UtcNow;
                    con.LastUpdateUserid      = modifiedBy.SmUserId;
                    owner.PrimaryContact      = con;
                }
                catch
                {
                    // do nothing
                }

                dbContext.Owners.Update(owner);
            }
        }
Esempio n. 11
0
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.Project oldObject, ref Models.Project instance, string systemId)
        {
            bool isNew = false;

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

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                isNew       = true;
                instance    = new Models.Project();
                instance.Id = oldObject.Project_Id;
                try
                {
                    // instance.ProjectId = oldObject.Reg_Dump_Trk;
                    try
                    {   //4 properties
                        instance.ProvincialProjectNumber = oldObject.Project_Num;
                        ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.Id == oldObject.Service_Area_Id);
                        District    dis         = dbContext.Districts.FirstOrDefault(x => x.Id == serviceArea.DistrictId);
                        instance.District   = dis;
                        instance.DistrictId = dis.Id;
                    }
                    catch (Exception e)
                    {
                        string iii = e.ToString();
                    }

                    try
                    {
                        instance.Name = oldObject.Job_Desc1;
                    }
                    catch (Exception e)
                    {
                        string i = e.ToString();
                    }
                    try
                    {
                        instance.Information = oldObject.Job_Desc2;
                    }
                    catch (Exception e)
                    {
                        string i = e.ToString();
                    }

                    try
                    {
                        instance.Notes = new List <Note>();
                        Models.Note note = new Note();
                        note.Text = new string(oldObject.Job_Desc2.Take(2048).ToArray());
                        note.IsNoLongerRelevant = true;
                        instance.Notes.Add(note);
                    }
                    catch (Exception e)
                    {
                        string i = e.ToString();
                    }

                    //  instance.RentalAgreements
                    // instance.RentalRequests = oldObject.
                    try
                    {   //9 properties
                        instance.CreateTimestamp = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch (Exception e)
                    {
                        instance.CreateTimestamp = DateTime.UtcNow;
                    }

                    instance.CreateUserid = createdBy.SmUserId;
                }
                catch (Exception e)
                {
                    string i = e.ToString();
                }

                dbContext.Projects.Add(instance);
            }
            else
            {
                instance = dbContext.Projects
                           .First(x => x.Id == oldObject.Project_Id);
                instance.LastUpdateUserid    = modifiedBy.SmUserId;
                instance.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.Projects.Update(instance);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Adding Rental Agreement Rate and Time Records to rental agreement
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="rentalAgreement"></param>
        /// <param name="workedDate"></param>
        /// <param name="systemId"></param>
        private static void AddingRateTimeForRentaAgreement(DbAppContext dbContext, EquipUsage oldObject,
                                                            ref RentalAgreement rentalAgreement, string workedDate, string systemId)
        {
            // adding rental agreement rates and time records:
            // the two are added together because time record reference rental agreement rate

            // adding general properties for Rental Agreement Rate
            DateTime lastUpdateTimestamp = DateTime.UtcNow;

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

            string lastUpdateUserid = oldObject.Created_By == null ? systemId : ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId).SmUserId;

            // adding general properties for Time Record
            DateTime workedDateTime;

            if (oldObject.Worked_Dt != null)
            {
                workedDateTime = DateTime.ParseExact(workedDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                workedDateTime = DateTime.UtcNow;
            }

            DateTime createdDate;

            if (oldObject.Created_Dt != null)
            {
                createdDate = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                createdDate = DateTime.UtcNow;
            }

            // adding three rates and hours using a Dictionary
            Dictionary <int, Pair> f = new Dictionary <int, Pair>();

            float rate   = (float)Decimal.Parse(oldObject.Rate ?? "0", System.Globalization.NumberStyles.Any);
            float rate2  = (float)Decimal.Parse(oldObject.Rate2 ?? "0", System.Globalization.NumberStyles.Any);
            float rate3  = (float)Decimal.Parse(oldObject.Rate3 ?? "0", System.Globalization.NumberStyles.Any);
            float hours  = (float)Decimal.Parse(oldObject.Hours ?? "0", System.Globalization.NumberStyles.Any);
            float hours2 = (float)Decimal.Parse(oldObject.Hours2 ?? "0", System.Globalization.NumberStyles.Any);
            float hours3 = (float)Decimal.Parse(oldObject.Hours3 ?? "0", System.Globalization.NumberStyles.Any);

            // add items to dictionary
            if (hours != 0.0 || rate != 0.0)
            {
                f.Add(1, new Pair(hours, rate));
            }

            if (hours2 != 0.0 || rate2 != 0.0)
            {
                f.Add(2, new Pair(hours2, rate2));
            }

            if (hours3 != 0.0 || rate3 != 0.0)
            {
                f.Add(3, new Pair(hours3, rate3));
            }

            // use var in foreach loop.
            int ii = 0;

            RentalAgreementRate [] rateA = new RentalAgreementRate[3];
            TimeRecord []          tRecA = new TimeRecord[3];

            foreach (var pair in f)
            {
                RentalAgreementRate exitingRate = rentalAgreement.RentalAgreementRates.FirstOrDefault(x => x.Rate == pair.Value.Rate);

                // rate does not exist
                if (exitingRate == null)
                {
                    // adding the new rate
                    rateA[ii] = new RentalAgreementRate
                    {
                        Comment             = "Import from BCBid",
                        IsAttachment        = false,
                        LastUpdateTimestamp = lastUpdateTimestamp,
                        LastUpdateUserid    = lastUpdateUserid,
                        CreateTimestamp     = createdDate,
                        CreateUserid        = lastUpdateUserid,
                        Rate = pair.Value.Rate
                    };

                    rentalAgreement.RentalAgreementRates.Add(rateA[ii]);

                    // add time Record
                    tRecA[ii] = new TimeRecord
                    {
                        EnteredDate         = lastUpdateTimestamp,
                        LastUpdateUserid    = lastUpdateUserid,
                        WorkedDate          = workedDateTime,
                        Hours               = pair.Value.Hours,
                        CreateTimestamp     = createdDate,
                        CreateUserid        = lastUpdateUserid,
                        RentalAgreementRate = rateA[ii]
                    };

                    rentalAgreement.TimeRecords.Add(tRecA[ii]);
                }
                else
                {
                    //the rate already existed which is exitingRate, no need to add rate, just add Time Record
                    TimeRecord existingTimeRec = rentalAgreement.TimeRecords.FirstOrDefault(x => x.WorkedDate == workedDateTime);

                    if (existingTimeRec == null)
                    {
                        // the new Time Record is added if it does not exist, otherwise, it already existed
                        tRecA[ii] = new TimeRecord
                        {
                            EnteredDate         = lastUpdateTimestamp,
                            LastUpdateUserid    = lastUpdateUserid,
                            WorkedDate          = workedDateTime,
                            Hours               = pair.Value.Hours,
                            CreateTimestamp     = createdDate,
                            CreateUserid        = lastUpdateUserid,
                            RentalAgreementRate = exitingRate
                        };

                        rentalAgreement.TimeRecords.Add(tRecA[ii]);
                    }
                }

                ii++;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="rentalAgreement"></param>
        /// <param name="note"></param>
        /// <param name="workedDate"></param>
        /// <param name="equips"></param>
        /// <param name="systemId"></param>
        private static void CopyToTimeRecorded(DbAppContext dbContext, EquipUsage oldObject,
                                               ref RentalAgreement rentalAgreement, string note, string workedDate, List <Equipment> equips, string systemId)
        {
            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (rentalAgreement == null)
            {
                rentalAgreement = new RentalAgreement
                {
                    RentalAgreementRates = new List <RentalAgreementRate>(),
                    TimeRecords          = new List <TimeRecord>()
                };

                Equipment equip = equips.FirstOrDefault(x => x.Id == oldObject.Equip_Id);

                if (equip != null)
                {
                    rentalAgreement.Equipment   = equip;
                    rentalAgreement.EquipmentId = equip.Id;
                }

                Models.Project proj = dbContext.Projects.FirstOrDefault(x => x.Id == oldObject.Project_Id);

                if (proj != null)
                {
                    rentalAgreement.Project   = proj;
                    rentalAgreement.ProjectId = proj.Id;
                }

                // adding rental agreement rates and Time_Records: The two are added together becase Time Record reference rental agreement rate.
                AddingRateTimeForRentaAgreement(dbContext, oldObject, ref rentalAgreement, workedDate, systemId);

                rentalAgreement.Status        = "Imported from BCBid";
                rentalAgreement.Note          = note;
                rentalAgreement.EquipmentRate = (float)Decimal.Parse(oldObject.Rate ?? "0", System.Globalization.NumberStyles.Any);

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

                if (oldObject.Created_Dt != null)
                {
                    try
                    {
                        rentalAgreement.CreateTimestamp = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        rentalAgreement.CreateTimestamp = DateTime.UtcNow;
                    }
                }

                rentalAgreement.CreateUserid = createdBy.SmUserId;
                dbContext.RentalAgreements.Add(rentalAgreement);
            }
            else
            {
                rentalAgreement = dbContext.RentalAgreements.First(x => x.Note == note);

                if (rentalAgreement.RentalAgreementRates == null)
                {
                    rentalAgreement.RentalAgreementRates = new List <RentalAgreementRate>();
                }

                if (rentalAgreement.TimeRecords == null)
                {
                    rentalAgreement.TimeRecords = new List <TimeRecord>();
                }

                AddingRateTimeForRentaAgreement(dbContext, oldObject, ref rentalAgreement, workedDate, systemId);
                rentalAgreement.LastUpdateUserid    = modifiedBy.SmUserId;
                rentalAgreement.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.RentalAgreements.Update(rentalAgreement);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Copy xml item to instance (table entries)
        /// Output is ServiceArea name
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        /// <param name="equipRentalRateNo"></param>
        /// <returns></returns>
        private static string CopyToInstance(DbAppContext dbContext, EquipType oldObject, ref DistrictEquipmentType instance, string systemId, float equipRentalRateNo)
        {
            string serviceAreaName = "";

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

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new DistrictEquipmentType {
                    Id = oldObject.Equip_Type_Id
                };

                string typeCode = "";

                try
                {
                    typeCode = oldObject.Equip_Type_Cd.Length >= 20 ? oldObject.Equip_Type_Cd.Substring(0, 20) : oldObject.Equip_Type_Cd;
                }
                catch
                {
                    // do nothing
                }

                ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.MinistryServiceAreaID == oldObject.Service_Area_Id);

                if (serviceArea != null)
                {
                    serviceAreaName = serviceArea.Name;
                    instance.DistrictEquipmentName = typeCode;

                    int      districtId = serviceArea.DistrictId ?? 0;
                    District dis        = dbContext.Districts.FirstOrDefault(x => x.RegionId == districtId);

                    if (dis != null)
                    {
                        instance.DistrictId = districtId;
                        instance.District   = dis;
                    }
                    else
                    {
                        // the District Id is not in the database
                        // (happens when the production data does not include district Other than "Lower Mainland" or all the districts)
                        return("ERROR");
                    }
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;

                if (oldObject.Equip_Type_Cd != null)
                {
                    EquipmentType eType = dbContext.EquipmentTypes.FirstOrDefault(x => (Math.Abs((x.BlueBookSection ?? 0.1) - equipRentalRateNo)) <= ErrowAllowed);

                    if (eType == null)
                    {
                        eType = dbContext.EquipmentTypes.FirstOrDefault(x => (Math.Abs((x.BlueBookSection ?? 0.1) - DefaultBlueBoxSection)) <= ErrowAllowed);
                    }

                    if (eType != null)
                    {
                        instance.EquipmentTypeId = eType.Id;
                    }
                }
            }

            return(serviceAreaName);
        }
Esempio n. 15
0
        /// <summary>
        /// Adding (3) Rental Agreement Rate and (3) Time Records to rental agreement
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="rentalAgreement"></param>
        /// <param name="systemId"></param>
        static private void addingRate_Time_For_RentaAgreement(DbAppContext dbContext, HETSAPI.Import.EquipUsage oldObject,
                                                               ref Models.RentalAgreement rentalAgreement, string workedDate, string systemId)
        {
            // Adding rental agreement rates and Time_Records: The two are added together becase Time Record reference rental agreement rate.
            Models.RentalAgreementRate rate = new RentalAgreementRate();
            Models.TimeRecord          tRec = new TimeRecord();

            //Adding general properties for RentalAgreement Rate
            DateTime lastUpdateTimestamp = DateTime.UtcNow;

            if (oldObject.Entered_Dt != null)
            {
                lastUpdateTimestamp = DateTime.ParseExact(oldObject.Entered_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            string lastUpdateUserid = oldObject.Created_By == null ? systemId : ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId).SmUserId;

            //Adding general properties for Time Records
            DateTime workedDateTime;

            if (oldObject.Worked_Dt != null)
            {
                workedDateTime = DateTime.ParseExact(workedDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                workedDateTime = DateTime.UtcNow;
            }

            DateTime createdDate;

            if (oldObject.Created_Dt != null)
            {
                createdDate = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
            }
            else
            {
                createdDate = DateTime.UtcNow;
            }

            //Adding three rates and hours using a Dictionary
            Dictionary <int, Pair> _f = new Dictionary <int, Pair>();
            float Rate   = (float)Decimal.Parse(oldObject.Rate == null ? "0" : oldObject.Rate, System.Globalization.NumberStyles.Any);
            float Rate2  = (float)Decimal.Parse(oldObject.Rate2 == null ? "0" : oldObject.Rate2, System.Globalization.NumberStyles.Any);
            float Rate3  = (float)Decimal.Parse(oldObject.Rate3 == null ? "0" : oldObject.Rate3, System.Globalization.NumberStyles.Any);
            float Hours  = (float)Decimal.Parse(oldObject.Hours == null ? "0" : oldObject.Hours, System.Globalization.NumberStyles.Any);
            float Hours2 = (float)Decimal.Parse(oldObject.Hours2 == null ? "0" : oldObject.Hours2, System.Globalization.NumberStyles.Any);
            float Hours3 = (float)Decimal.Parse(oldObject.Hours3 == null ? "0" : oldObject.Hours3, System.Globalization.NumberStyles.Any);

            // Add items to dictionary.

            if (Hours != 0.0 || Rate != 0.0)
            {
                _f.Add(1, new Pair(Hours, Rate));
            }
            if (Hours2 != 0.0 || Rate2 != 0.0)
            {
                _f.Add(2, new Pair(Hours2, Rate2));
            }
            if (Hours3 != 0.0 || Rate3 != 0.0)
            {
                _f.Add(3, new Pair(Hours3, Rate3));
            }

            // Use var in foreach loop.
            int ii = 0;

            Models.RentalAgreementRate [] rate_a = new RentalAgreementRate[3];
            Models.TimeRecord []          tRec_a = new TimeRecord[3];
            foreach (var pair in _f)
            {
                Models.RentalAgreementRate exitingRate = rentalAgreement.RentalAgreementRates.FirstOrDefault(x => x.Rate == pair.Value.Rate);
                if (exitingRate == null) //rate does not exist
                {                        //  Adding the new rate
                    rate_a[ii]                     = new RentalAgreementRate();
                    rate_a[ii].Comment             = "Import from BCBid";
                    rate_a[ii].IsAttachment        = false;
                    rate_a[ii].LastUpdateTimestamp = lastUpdateTimestamp;
                    rate_a[ii].LastUpdateUserid    = lastUpdateUserid;
                    rate_a[ii].CreateTimestamp     = createdDate;
                    rate_a[ii].CreateUserid        = lastUpdateUserid;
                    rate_a[ii].Rate                = pair.Value.Rate;
                    rentalAgreement.RentalAgreementRates.Add(rate_a[ii]);
                    //Also add time Record
                    tRec_a[ii]                     = new TimeRecord();
                    tRec_a[ii].EnteredDate         = lastUpdateTimestamp;
                    tRec_a[ii].LastUpdateUserid    = lastUpdateUserid;
                    tRec_a[ii].WorkedDate          = workedDateTime;
                    tRec_a[ii].Hours               = pair.Value.Hours;
                    tRec_a[ii].CreateTimestamp     = createdDate;
                    tRec_a[ii].CreateUserid        = lastUpdateUserid;
                    tRec_a[ii].RentalAgreementRate = rate_a[ii];
                    rentalAgreement.TimeRecords.Add(tRec_a[ii]);
                }
                else
                {   //the rate already existed which is exitingRate, no need to add rate, just add Time Record
                    Models.TimeRecord existingTimeRec = rentalAgreement.TimeRecords.FirstOrDefault(x => x.WorkedDate == workedDateTime);
                    if (existingTimeRec == null)
                    {   //The new Time Record  is added if it does not existm, otherwise, it's already existed.
                        tRec_a[ii]                     = new TimeRecord();
                        tRec_a[ii].EnteredDate         = lastUpdateTimestamp;
                        tRec_a[ii].LastUpdateUserid    = lastUpdateUserid;
                        tRec_a[ii].WorkedDate          = workedDateTime;
                        tRec_a[ii].Hours               = pair.Value.Hours;
                        tRec_a[ii].CreateTimestamp     = createdDate;
                        tRec_a[ii].CreateUserid        = lastUpdateUserid;
                        tRec_a[ii].RentalAgreementRate = exitingRate;
                        rentalAgreement.TimeRecords.Add(tRec_a[ii]);
                    }
                }
                ii++;
            }
            // Ended adding Rental Agreement rates and time records.
        }
Esempio n. 16
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, Project oldObject, ref Models.Project instance, string systemId)
        {
            if (oldObject.Project_Id <= 0)
            {
                return;
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new Models.Project {
                    Id = oldObject.Project_Id
                };

                try
                {
                    try
                    {   //4 properties
                        instance.ProvincialProjectNumber = oldObject.Project_Num;
                        ServiceArea serviceArea = dbContext.ServiceAreas.FirstOrDefault(x => x.Id == oldObject.Service_Area_Id);
                        District    dis         = dbContext.Districts.FirstOrDefault(x => x.Id == serviceArea.DistrictId);

                        if (dis != null)
                        {
                            instance.District   = dis;
                            instance.DistrictId = dis.Id;
                        }
                        else
                        {
                            // this means that the District Id is not in the database
                            // (happens when the production data does not include district Other than "Lower Mainland" or all the districts)
                            return;
                        }
                    }
                    catch
                    {
                        // do nothing
                    }

                    try
                    {
                        instance.Name = oldObject.Job_Desc1;
                    }
                    catch
                    {
                        // do nothing
                    }

                    try
                    {
                        instance.Information = oldObject.Job_Desc2;
                    }
                    catch
                    {
                        // do nothing
                    }

                    try
                    {
                        instance.Notes = new List <Note>();

                        Note note = new Note
                        {
                            Text = new string(oldObject.Job_Desc2.Take(2048).ToArray()),
                            IsNoLongerRelevant = true
                        };

                        instance.Notes.Add(note);
                    }
                    catch
                    {
                        // do nothing
                    }

                    try
                    {
                        instance.CreateTimestamp = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        instance.CreateTimestamp = DateTime.UtcNow;
                    }

                    instance.CreateUserid = createdBy.SmUserId;
                }
                catch
                {
                    // do nothing
                }

                dbContext.Projects.Add(instance);
            }
            else
            {
                instance = dbContext.Projects.First(x => x.Id == oldObject.Project_Id);
                instance.LastUpdateUserid    = modifiedBy.SmUserId;
                instance.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.Projects.Update(instance);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(PerformContext performContext, DbAppContext dbContext, Equip oldObject, ref Equipment instance, string systemId)
        {
            if (oldObject.Equip_Id <= 0)
            {
                return;
            }

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (instance == null)
            {
                instance = new Equipment
                {
                    Id          = oldObject.Equip_Id,
                    ArchiveCode = oldObject.Archive_Cd == null
                        ? ""
                        : new string(oldObject.Archive_Cd.Take(50).ToArray()),
                    ArchiveReason = oldObject.Archive_Reason == null
                        ? ""
                        : new string(oldObject.Archive_Reason.Take(2048).ToArray()),
                    LicencePlate = oldObject.Licence == null ? "" : new string(oldObject.Licence.Take(20).ToArray())
                };

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

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

                if (oldObject.Comment != null)
                {
                    instance.Notes = new List <Note>();

                    Note note = new Note
                    {
                        Text = new string(oldObject.Comment.Take(2048).ToArray()),
                        IsNoLongerRelevant = true
                    };

                    instance.Notes.Add(note);
                }

                if (oldObject.Area_Id != null)
                {
                    LocalArea area = dbContext.LocalAreas.FirstOrDefault(x => x.Id == oldObject.Area_Id);
                    if (area != null)
                    {
                        instance.LocalArea = area;
                    }
                }

                if (oldObject.Equip_Type_Id != null)
                {
                    //Equipment_TYPE_ID is copied to the table of HET_DISTRICT_DISTRICT_TYPE as key
                    DistrictEquipmentType equipType = dbContext.DistrictEquipmentTypes.FirstOrDefault(x => x.Id == oldObject.Equip_Type_Id);

                    if (equipType != null)
                    {
                        instance.DistrictEquipmentType   = equipType;
                        instance.DistrictEquipmentTypeId = oldObject.Equip_Type_Id;
                    }
                }

                instance.EquipmentCode = oldObject.Equip_Cd == null ? "" : new string(oldObject.Equip_Cd.Take(25).ToArray());
                instance.Model         = oldObject.Model == null ? "" : new string(oldObject.Model.Take(50).ToArray());
                instance.Make          = oldObject.Make == null ? "" : new string(oldObject.Make.Take(50).ToArray());
                instance.Year          = oldObject.Year == null ? "" : new string(oldObject.Year.Take(15).ToArray());
                instance.Operator      = oldObject.Operator == null ? "" : new string(oldObject.Operator.Take(255).ToArray());
                instance.SerialNumber  = oldObject.Serial_Num == null ? "" : new string(oldObject.Serial_Num.Take(100).ToArray());
                instance.Status        = oldObject.Status_Cd == null ? "" : new string(oldObject.Status_Cd.Take(50).ToArray());

                if (oldObject.Pay_Rate != null)
                {
                    try
                    {
                        instance.PayRate = float.Parse(oldObject.Pay_Rate.Trim());
                    }
                    catch
                    {
                        instance.PayRate = (float)0.0;
                    }
                }

                if (instance.Seniority != null)
                {
                    try
                    {
                        instance.Seniority = float.Parse(oldObject.Seniority.Trim());
                    }
                    catch
                    {
                        instance.Seniority = (float)0.0;
                    }
                }

                // find the owner which is referenced in the equipment of the xml file entry Through ImportMaps because owner_ID is not prop_ID
                ImportMap map = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == ImportOwner.OldTable && x.OldKey == oldObject.Owner_Popt_Id.ToString());

                if (map != null)
                {
                    Models.Owner owner = dbContext.Owners.FirstOrDefault(x => x.Id == map.NewKey);
                    if (owner != null)
                    {
                        instance.Owner = owner;
                        Contact con = dbContext.Contacts.FirstOrDefault(x => x.Id == owner.PrimaryContactId);

                        // update owner contact address
                        if (con != null)
                        {
                            try
                            {
                                con.Address1   = oldObject.Addr1;
                                con.Address2   = oldObject.Addr2;
                                con.City       = oldObject.City;
                                con.PostalCode = oldObject.Postal;
                                con.Province   = "BC";
                                dbContext.Contacts.Update(con);
                            }
                            catch (Exception e)
                            {
                                performContext.WriteLine("Error mapping data " + e.Message);
                            }
                        }
                    }
                }

                if (oldObject.Seniority != null)
                {
                    try
                    {
                        instance.Seniority = float.Parse(oldObject.Seniority.Trim());
                    }
                    catch
                    {
                        instance.Seniority = (float)0.0;
                    }
                }

                if (oldObject.Num_Years != null)
                {
                    try
                    {
                        instance.YearsOfService = float.Parse(oldObject.Num_Years.Trim());
                    }
                    catch
                    {
                        instance.YearsOfService = (float)0.0;
                    }
                }

                if (oldObject.Block_Num != null)
                {
                    try
                    {
                        instance.BlockNumber = decimal.ToInt32(Decimal.Parse(oldObject.Block_Num, System.Globalization.NumberStyles.Float));
                    }
                    catch
                    {
                        // do nothing
                    }
                }

                if (oldObject.Size != null)
                {
                    try
                    {
                        instance.Size = oldObject.Size;
                    }
                    catch
                    {
                        // do nothing
                    }
                }

                if (oldObject.YTD1 != null && oldObject.YTD2 != null && oldObject.YTD3 != null)
                {
                    try
                    {
                        instance.ServiceHoursLastYear = (float)Decimal.Parse(oldObject.YTD1, System.Globalization.NumberStyles.Any);
                    }
                    catch
                    {
                        instance.ServiceHoursLastYear = (float)0.0;
                    }
                    try
                    {
                        instance.ServiceHoursTwoYearsAgo   = (float)Decimal.Parse(oldObject.YTD2, System.Globalization.NumberStyles.Any);
                        instance.ServiceHoursThreeYearsAgo = (float)Decimal.Parse(oldObject.YTD3, System.Globalization.NumberStyles.Any);
                    }
                    catch
                    {
                        instance.ServiceHoursTwoYearsAgo   = (float)0.0;
                        instance.ServiceHoursThreeYearsAgo = (float)0.0;
                    }
                }

                instance.CreateTimestamp = DateTime.UtcNow;
                instance.CreateUserid    = createdBy.SmUserId;
                dbContext.Equipments.Add(instance);
            }
            else
            {
                instance = dbContext.Equipments.First(x => x.Id == oldObject.Equip_Id);
                instance.LastUpdateUserid = modifiedBy.SmUserId;

                try
                {
                    instance.LastUpdateUserid    = modifiedBy.SmUserId;
                    instance.LastUpdateTimestamp = DateTime.ParseExact(oldObject.Modified_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception e)
                {
                    performContext.WriteLine("Error mapping data " + e.Message);
                }

                dbContext.Equipments.Update(instance);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Copy user instance
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="user"></param>
        /// <param name="systemId"></param>
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.User_HETS oldObject, ref Models.User user, string systemId)
        {
            bool isNew = false;

            string smUserId;
            int    service_Area_Id;

            int startPos = oldObject.User_Cd.IndexOf(@"\") + 1;

            try
            {
                service_Area_Id = oldObject.Service_Area_Id;
                smUserId        = oldObject.User_Cd.Substring(startPos).Trim();
            }
            catch
            {
                return;
            }

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);
            if (createdBy.SmUserId == smUserId)
            {
                user = createdBy;
                return;
            }
            if (modifiedBy.SmUserId == smUserId)
            {
                user = modifiedBy;
                return;
            }

            Models.UserRole userRole = new UserRole();

            string authority;

            try
            {
                authority = oldObject.Authority.Trim();
            }
            catch
            {
                authority = ""; // Regular User
            }


            int roleId = ImportUtility.GetRoleIdFromAuthority(authority);

            Models.User user1 = dbContext.Users.FirstOrDefault(x => x.SmUserId == smUserId);

            ServiceArea serArea = dbContext.ServiceAreas
                                  .Include(x => x.District)
                                  .FirstOrDefault(x => x.MinistryServiceAreaID == service_Area_Id);

            if (user1 == null)
            {
                isNew = true;
                if (user == null)
                {
                    user = new User();
                }

                try
                {
                    user.SmUserId   = smUserId;
                    user.District   = serArea.District;
                    user.DistrictId = serArea.DistrictId;
                }
                catch
                {
                }

                user.CreateTimestamp = DateTime.UtcNow;
                user.CreateUserid    = createdBy.SmUserId;


                // The followings are the data mapping
                // user.Email = oldObject.
                // user.GivenName
                // user.Surname

                //Add user Role  -  Role Id is limited to 1, or 2
                if (roleId > 2)
                {
                    roleId = 1;
                }
                userRole.Role            = dbContext.Roles.First(x => x.Id == roleId);
                userRole.CreateTimestamp = DateTime.UtcNow;
                userRole.ExpiryDate      = DateTime.UtcNow.AddMonths(12);
                userRole.CreateUserid    = createdBy.SmUserId;
                userRole.EffectiveDate   = DateTime.UtcNow.AddDays(-1);

                user.UserRoles = new List <UserRole>();
                user.UserRoles.Add(userRole);
                dbContext.Users.Add(user);
            }
            else
            {
                user = dbContext.Users
                       .Include(x => x.UserRoles)
                       .Include(x => x.GroupMemberships)
                       .First(x => x.SmUserId == smUserId);

                // if the user does not have the user role, add the user role
                if (user.UserRoles == null)
                {
                    user.UserRoles = new List <UserRole>();
                }
                // If the role does not exist for the user, add the user role for the user
                if (user.UserRoles.FirstOrDefault(x => x.RoleId == roleId) == null)
                {
                    userRole.Role            = dbContext.Roles.First(x => x.Id == roleId);
                    userRole.CreateTimestamp = DateTime.UtcNow;
                    userRole.ExpiryDate      = DateTime.UtcNow.AddMonths(12);
                    userRole.CreateUserid    = createdBy.SmUserId;
                    userRole.EffectiveDate   = DateTime.UtcNow.AddDays(-1);
                    user.UserRoles.Add(userRole);
                }
                user.LastUpdateUserid = createdBy.SmUserId;
                user.CreateTimestamp  = DateTime.UtcNow;
                user.Active           = true;
                dbContext.Users.Update(user);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="user"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, UserHets oldObject, ref User user, string systemId)
        {
            string smUserId;
            int    serviceAreaId;

            int startPos = oldObject.User_Cd.IndexOf(@"\", StringComparison.Ordinal) + 1;

            try
            {
                serviceAreaId = oldObject.Service_Area_Id;
                smUserId      = oldObject.User_Cd.Substring(startPos).Trim();
            }
            catch
            {
                return;
            }

            // add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId);
            User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            if (createdBy.SmUserId == smUserId)
            {
                user = createdBy;
                return;
            }

            if (modifiedBy.SmUserId == smUserId)
            {
                user = modifiedBy;
                return;
            }

            UserRole userRole = new UserRole();

            string authority;

            try
            {
                authority = oldObject.Authority.Trim();
            }
            catch
            {
                // regular User
                authority = "";
            }


            int roleId = ImportUtility.GetRoleIdFromAuthority(authority);

            User user1 = dbContext.Users.FirstOrDefault(x => x.SmUserId == smUserId);

            ServiceArea serArea = dbContext.ServiceAreas
                                  .Include(x => x.District)
                                  .FirstOrDefault(x => x.MinistryServiceAreaID == serviceAreaId);

            if (user1 == null)
            {
                if (user == null)
                {
                    user = new User();
                }

                try
                {
                    user.SmUserId = smUserId;

                    if (serArea != null)
                    {
                        user.District   = serArea.District;
                        user.DistrictId = serArea.DistrictId;
                    }
                }
                catch
                {
                    // do nothing
                }

                user.CreateTimestamp = DateTime.UtcNow;
                user.CreateUserid    = createdBy.SmUserId;

                //a dd user Role - Role Id is limited to 1, or 2
                if (roleId > 2)
                {
                    roleId = 1;
                }

                userRole.Role            = dbContext.Roles.First(x => x.Id == roleId);
                userRole.CreateTimestamp = DateTime.UtcNow;
                userRole.ExpiryDate      = DateTime.UtcNow.AddMonths(12);
                userRole.CreateUserid    = createdBy.SmUserId;
                userRole.EffectiveDate   = DateTime.UtcNow.AddDays(-1);

                user.UserRoles = new List <UserRole> {
                    userRole
                };
                dbContext.Users.Add(user);
            }
            else
            {
                user = dbContext.Users
                       .Include(x => x.UserRoles)
                       .Include(x => x.GroupMemberships)
                       .First(x => x.SmUserId == smUserId);

                // if the user does not have the user role, add the user role
                if (user.UserRoles == null)
                {
                    user.UserRoles = new List <UserRole>();
                }

                // if the role does not exist for the user, add the user role for the user
                if (user.UserRoles.FirstOrDefault(x => x.RoleId == roleId) == null)
                {
                    userRole.Role            = dbContext.Roles.First(x => x.Id == roleId);
                    userRole.CreateTimestamp = DateTime.UtcNow;
                    userRole.ExpiryDate      = DateTime.UtcNow.AddMonths(12);
                    userRole.CreateUserid    = createdBy.SmUserId;
                    userRole.EffectiveDate   = DateTime.UtcNow.AddDays(-1);
                    user.UserRoles.Add(userRole);
                }

                user.LastUpdateUserid = createdBy.SmUserId;
                user.CreateTimestamp  = DateTime.UtcNow;
                user.Active           = true;
                dbContext.Users.Update(user);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Copy Block item of LocalAreaRotationList item
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="systemId"></param>
        /// <param name="oldUniqueId"></param>
        static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.Block oldObject,
                                           ref Models.LocalAreaRotationList instance, string systemId, string oldUniqueId)
        {
            bool isNew = false;

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

            //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database
            Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, "", systemId);
            Models.User createdBy  = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

            int areaId          = oldObject.Area_Id ?? 0;
            int equipmentTypeId = oldObject.Equip_Type_Id ?? 0;
            int blockNum        = Convert.ToInt32(float.Parse(oldObject.Block_Num == null ? "0.0" : oldObject.Block_Num));
            int cyclekNum       = Convert.ToInt32(float.Parse(oldObject.Cycle_Num == null ? "0.0" : oldObject.Cycle_Num));
            int maxCycle        = Convert.ToInt32(float.Parse(oldObject.Max_Cycle == null ? "0.0" : oldObject.Max_Cycle));
            int lastHiredEqupId = oldObject.Last_Hired_Equip_Id ?? 0;

            if (instance == null)
            {
                isNew    = true;
                instance = new Models.LocalAreaRotationList();
                // instance.ProjectId = oldObject.Reg_Dump_Trk;
                DistrictEquipmentType disEquipType = dbContext.DistrictEquipmentTypes.FirstOrDefault(x => x.Id == equipmentTypeId);
                if (disEquipType != null)
                {
                    instance.DistrictEquipmentType   = disEquipType;
                    instance.DistrictEquipmentTypeId = disEquipType.Id;
                }

                // Extract AskNextBlock*Id which is the secondary key of Equip.Id
                int equipId = oldObject.Last_Hired_Equip_Id ?? 0;
                if (dbContext.Equipments.Any(x => x.Id == equipId))
                {
                    switch (blockNum)
                    {
                    case 1:
                        instance.AskNextBlockOpenId = equipId;
                        break;

                    case 2:
                        instance.AskNextBlock1Id = equipId;
                        break;

                    case 3:
                        instance.AskNextBlock2Id = equipId;
                        break;

                    default:
                        break;
                    }
                }

                instance.CreateUserid = createdBy.SmUserId;
                if (oldObject.Created_Dt != null)
                {
                    instance.CreateTimestamp = DateTime.ParseExact(oldObject.Created_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                }

                dbContext.LocalAreaRotationLists.Add(instance);
            }
            else
            {
                // Updating the existing instance - but how to locate it? There is(are) no unique key(s) for that
            }
        }