예제 #1
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="instance"></param>
        /// <param name="equips"></param>
        /// <param name="systemId"></param>
        private static void CopyToInstance(DbAppContext dbContext, EquipAttach oldObject, ref EquipmentAttachment instance,
                                           List <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
            User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId);

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

                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;
                instance.LastUpdateTimestamp = DateTime.UtcNow;
                dbContext.EquipmentAttachments.Update(instance);
            }
        }
예제 #2
0
        /// <summary>
        /// Map data
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="oldObject"></param>
        /// <param name="equipAttach"></param>
        /// <param name="systemId"></param>
        /// <param name="maxEquipAttachIndex"></param>
        private static void CopyToInstance(DbAppContext dbContext, EquipAttach oldObject, ref EquipmentAttachment equipAttach,
                                           string systemId, ref int maxEquipAttachIndex)
        {
            try
            {
                if (oldObject.Equip_Id <= 0)
                {
                    return;
                }

                equipAttach = new EquipmentAttachment {
                    Id = ++maxEquipAttachIndex
                };

                // ************************************************
                // get the imported equipment record map
                // ************************************************
                string tempId = oldObject.Equip_Id.ToString();

                ImportMap map = dbContext.ImportMaps.AsNoTracking()
                                .FirstOrDefault(x => x.OldKey == tempId &&
                                                x.OldTable == ImportEquip.OldTable &&
                                                x.NewTable == ImportEquip.NewTable);

                if (map == null)
                {
                    return; // ignore and move to the next record
                }

                // ************************************************
                // get the equipment record
                // ************************************************
                Equipment equipment = dbContext.Equipments.AsNoTracking()
                                      .FirstOrDefault(x => x.Id == map.NewKey);

                if (equipment == null)
                {
                    throw new ArgumentException(string.Format("Cannot locate Equipment record (EquipAttach Equip Id: {0}", tempId));
                }

                // ************************************************
                // set the equipment attachment attributes
                // ************************************************
                int tempEquipmentId = equipment.Id;
                equipAttach.EquipmentId = tempEquipmentId;

                string tempDescription = ImportUtility.CleanString(oldObject.Attach_Desc);

                if (string.IsNullOrEmpty(tempDescription))
                {
                    return;                                        // don't add blank attachments
                }
                tempDescription         = ImportUtility.GetCapitalCase(tempDescription);
                equipAttach.Description = tempDescription;

                if (oldObject.Attach_Seq_Num != null)
                {
                    string tempSequence = oldObject.Attach_Seq_Num.ToString();
                    equipAttach.TypeName = tempSequence;
                }

                // ***********************************************
                // create equipment attachment
                // ***********************************************
                equipAttach.AppCreateUserid        = systemId;
                equipAttach.AppCreateTimestamp     = DateTime.UtcNow;
                equipAttach.AppLastUpdateUserid    = systemId;
                equipAttach.AppLastUpdateTimestamp = DateTime.UtcNow;

                dbContext.EquipmentAttachments.Add(equipAttach);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("***Error*** - Equipment Attachment: " + equipAttach.Description);
                Debug.WriteLine("***Error*** - Master Equipment Attachment Index: " + maxEquipAttachIndex);
                Debug.WriteLine(ex.Message);
                throw;
            }
        }