예제 #1
0
        public bool CheckExistingAssetOwner(Guid assetGuid)
        {
            var query  = $"select count(1) from md_asset_AssetOwner where fk_AssetUID = {assetGuid.ToStringWithoutHyphens().WrapWithUnhex()}";
            var result = _transaction.Get <string>(query);

            return(Convert.ToInt32(result.FirstOrDefault()) > 0);
        }
예제 #2
0
        public void GetCustomerUser_ValidCustomerUser_ReturnsResult()
        {
            //Arrange
            var customerUser = new DbUserCustomer
            {
                fk_CustomerID  = 88,
                fk_CustomerUID = Guid.NewGuid(),
                fk_UserUID     = Guid.NewGuid(),
                LastUserUTC    = DateTime.UtcNow,
                UserCustomerID = 123
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var assetCustomerCompareLogic = new CompareLogic(config);

            transaction.Get <DbUserCustomer>(Arg.Any <string>()).Returns(new List <DbUserCustomer> {
                customerUser
            });

            //Act
            var resultData = userCustomerService.GetCustomerUser(customerUser.fk_CustomerUID, customerUser.fk_UserUID);

            //Arrange
            Assert.NotNull(resultData);
            ComparisonResult compareResult = assetCustomerCompareLogic.Compare(customerUser, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
예제 #3
0
        public void GetAssetCustomer_ValidAssetCustomer_ReturnsResult()
        {
            //Arrange
            var assetCustomer = new DbAssetCustomer
            {
                AssetCustomerID        = 1,
                Fk_CustomerUID         = Guid.NewGuid(),
                Fk_AssetUID            = Guid.NewGuid(),
                fk_AssetRelationTypeID = 0,
                LastCustomerUTC        = DateTime.UtcNow
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var assetCustomerCompareLogic = new CompareLogic(config);

            transaction.Get <DbAssetCustomer>(Arg.Any <string>()).Returns(new List <DbAssetCustomer> {
                assetCustomer
            });

            //Act
            var resultData = customerAssetService.GetAssetCustomer(assetCustomer.Fk_CustomerUID, assetCustomer.Fk_AssetUID);

            //Arrange
            Assert.NotNull(resultData);
            ComparisonResult compareResult = assetCustomerCompareLogic.Compare(assetCustomer, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
예제 #4
0
        public DbAssetCustomer GetAssetCustomer(Guid customerUid, Guid assetUid)
        {
            var getCustomerAssetQuery = "SELECT AssetCustomerID,Fk_CustomerUID,Fk_AssetUID," +
                                        "fk_AssetRelationTypeID,LastCustomerUTC FROM md_customer_CustomerAsset WHERE Fk_CustomerUID = {0}" +
                                        " AND Fk_AssetUID = {1};";

            return(transaction.Get <DbAssetCustomer>(string.Format(getCustomerAssetQuery,
                                                                   customerUid.ToStringAndWrapWithUnhex(), assetUid.ToStringAndWrapWithUnhex()))?.FirstOrDefault());
        }
예제 #5
0
        public DbUserCustomer GetCustomerUser(Guid customerUid, Guid userUid)
        {
            var getUserCustomerQuery = "SELECT UserCustomerID,fk_UserUID,fk_CustomerUID,fk_CustomerID," +
                                       "LastUserUTC FROM md_customer_CustomerUser WHERE fk_CustomerUID = {0} AND fk_UserUID = {1};";

            return(transaction.Get <DbUserCustomer>(string.Format(getUserCustomerQuery,
                                                                  customerUid.ToStringAndWrapWithUnhex(),
                                                                  userUid.ToStringAndWrapWithUnhex()))?.FirstOrDefault());
        }
예제 #6
0
        public WorkDefinitionDto GetWorkDefinition(Guid assetUID)
        {
            string query  = @"SELECT awd.fk_AssetUID as AssetUID, awd.InsertUTC, awd.SwitchNumber, awd.SwitchWorkStartState, wdt.Description WorkDefinitionType 
							FROM md_asset_AssetWorkDefinition awd 
							INNER JOIN md_asset_WorkDefinitionType wdt ON wdt.WorkDefinitionTypeID = awd.fk_WorkDefinitionTypeID WHERE awd.fk_AssetUID = UNHEX('{0}') 
							ORDER BY awd.StartDate DESC LIMIT 1;"                            ;
            var    result = _transaction.Get <WorkDefinitionDto>(string.Format(query, assetUID.ToString("N")));

            return(result.FirstOrDefault());
        }
예제 #7
0
        public List <Guid> GetDeviceDetailsBySerialNumberAndType(string serialNumber, string type)
        {
            var deviceQuery = string.Format(Queries.GET_DEVICE_QUERY, serialNumber, deviceTypesCache.First(x => string.Equals(x.Key, type, StringComparison.InvariantCultureIgnoreCase)).Value.DeviceTypeID);

            var deviceUids = transactions.Get <string>(deviceQuery);

            //return !string.IsNullOrEmpty(deviceUid) ? new Guid(deviceUid) : Guid.Empty;

            return(deviceUids.Select(x => Guid.Parse(x)).ToList());
        }
예제 #8
0
        public List <AssetSettingsGetDBResponse> GetAssetUtilizationTargetRunTimeByStartDateAndAssetUID(string AssetUIDs, DateTime startDate, DateTime endDate)
        {
            try
            {
                var sql = string.Format(@"Select * From (Select HEX(AWC.fk_AssetUID) As AssetID, HEX(AWC.AssetWeeklyConfigUID) As AssetWeeklyConfigUID, AWC.SundayConfigValue As Sunday, AWC.MondayConfigValue As Monday, AWC.TuesdayConfigValue As Tuesday, 
                                                AWC.WednesdayConfigValue AS Wednesday, AWC.ThursdayConfigValue AS Thursday, AWC.FridayConfigValue As Friday, 
                                                AWC.SaturdayConfigValue AS Saturday, AWC.StartDate as StartDate, AWC.EndDate as EndDate, ACT.ConfigTypeName AS 'ConfigType' FRom md_asset_AssetWeeklyConfig AWC 
                                                Inner Join md_asset_AssetConfigType ACT On ACT.AssetConfigTypeID = AWC.fk_AssetConfigTypeID And ACT.ConfigTypeName IN ('" +
                                        AssetTargetType.RuntimeHours.ToString() + "', '" + AssetTargetType.IdletimeHours.ToString() + @"')
                                                Where AWC.fk_AssetUID In ({0}) AND ('{1}' Between StartDate And EndDate OR '{2}' Between StartDate And EndDate) Order By AWC.StartDate)A 
                                                UNION
                                                Select * From (Select HEX(AWC.fk_AssetUID) As AssetID, HEX(AWC.AssetWeeklyConfigUID) As AssetWeeklyConfigUID, AWC.SundayConfigValue As Sunday, AWC.MondayConfigValue As Monday, AWC.TuesdayConfigValue As Tuesday, 
                                                AWC.WednesdayConfigValue AS Wednesday, AWC.ThursdayConfigValue AS Thursday, AWC.FridayConfigValue As Friday, 
                                                AWC.SaturdayConfigValue AS Saturday, AWC.StartDate as StartDate, AWC.EndDate as EndDate, ACT.ConfigTypeName AS 'ConfigType' FRom md_asset_AssetWeeklyConfig AWC 
                                                Inner Join md_asset_AssetConfigType ACT On ACT.AssetConfigTypeID = AWC.fk_AssetConfigTypeID And ACT.ConfigTypeName IN ('" +
                                        AssetTargetType.RuntimeHours.ToString() + "', '" + AssetTargetType.IdletimeHours.ToString() + @"')
                                                Where AWC.fk_AssetUID In ({0}) AND (StartDate Between '{1}' AND '{2}' OR EndDate Between '{1}' AND '{2}') Order By AWC.StartDate ASC) B",
                                        AssetUIDs, startDate.ToDateTimeStringWithYearMonthDayFormat(), endDate.ToDateTimeStringWithYearMonthDayFormat());

                _loggingService.Debug(string.Format("Data Access requested for the query {0}", sql), "WeeklyAssetSettingsRepository.GetAssetUtilizationTargetRunTimeByStartDateAndAssetUID");

                return(_transaction.Get <AssetSettingsGetDBResponse>(sql).ToList());
            }
            catch (Exception e)
            {
                throw;
            }
        }
예제 #9
0
        public void Check_ExistingAssetOwner(string avail, bool isExist)
        {
            //Arrange
            _transaction.Get <string>(Arg.Any <string>()).Returns(x => {
                return(new List <string>()
                {
                    avail
                });
            });

            //Act
            var result = _assetOwnerServices.CheckExistingAssetOwner(new Guid());

            //Assert
            Assert.Equal(result, isExist);
        }
예제 #10
0
        public void GetNullECMInfo()
        {
            //Arrange
            _transaction.Get <AssetECM>(Arg.Any <string>()).Returns(x => {
                return(new List <AssetECM>()
                {
                    new AssetECM()
                });
            });

            //Act
            var ecmData = _assetECMServices.GetAssetECMInfo(new Guid());

            //Assert
            Assert.Null(ecmData[0].AssetECMInfoUID);
        }
예제 #11
0
        private void GetServicePlan()
        {
            var readAllServiceViewQuery =
                "select st.Name,st.ServiceTypeID,stf.FamilyName from md_subscription_ServiceType st inner join md_subscription_ServiceTypeFamily stf on st.fk_ServiceTypeFamilyID = stf.ServiceTypeFamilyID";
            IEnumerable <ServiceView> serviceView = transaction.Get <ServiceView>(readAllServiceViewQuery);

            foreach (var service in serviceView)
            {
                var familyname = service.FamilyName.ToLower();
                switch (familyname)
                {
                case "asset":
                    _assetSubscriptionTypeCache.Add(service.Name, service.ServiceTypeID);
                    break;

                case "customer":
                    _customerSubscriptionTypeCache.Add(service.Name, service.ServiceTypeID);
                    break;

                case "project":
                    _projectSubscriptionTypeCache.Add(service.Name, service.ServiceTypeID);
                    break;

                default:
                    throw new Exception("ServiceTypeFamily does not exist");
                }
            }
        }
예제 #12
0
        public DbAccount GetAccount(Guid accountUid)
        {
            var getAccountQuery = "select CustomerAccountID,CustomerAccountUID,BSSID,AccountName," +
                                  "NetworkCustomerCode,DealerAccountCode,fk_ParentCustomerUID,fk_ChildCustomerUID,RowUpdatedUTC " +
                                  "from md_customer_CustomerAccount where CustomerAccountUID = {0}";

            return(transaction.Get <DbAccount>(string.Format(getAccountQuery,
                                                             accountUid.ToStringAndWrapWithUnhex()))?.FirstOrDefault());
        }
예제 #13
0
        public List <AssetECM> GetAssetECMInfo(Guid assetGuid)
        {
            var readAssetECMQuery = $"SELECT ECMSerialNumber AS SerialNumber, FirmwarePartNumber AS PartNumber, ECMDescription AS Description," +
                                    $"IsSyncClockEnabled AS SyncClockEnabled,SyncClockLevel AS SyncClockLevel " +
                                    $"FROM msg_md_assetecm_AssetEcmInfo ecm " +
                                    $"INNER JOIN md_asset_AssetDevice ad on ecm.AssetUID = ad.fk_AssetUID and ecm.DeviceUID = ad.fk_DeviceUID WHERE AssetUID = {assetGuid.ToStringWithoutHyphens().WrapWithUnhex()} " +
                                    $"and ECMSerialNumber <> 'Unavailable' ORDER BY ECMSerialNumber; ";

            return(_transaction.Get <AssetECM>(readAssetECMQuery).ToList());
        }
예제 #14
0
 public ClientModel.Asset GetAsset(Guid assetUID)
 {
     try
     {
         string assetQuery = $"SELECT Hex(AssetUID) As AssetUID, AssetName, LegacyAssetID, SerialNumber, MakeCode, Model, AssetTypeName As AssetType, IconKey, " +
                             $"EquipmentVIN, ModelYear, StatusInd, Hex(OwningCustomerUID) As OwningCustomerUID, ObjectType, Category, ProjectStatus, " +
                             $"SortField, Source, UserEnteredRuntimeHours, Classification, PlanningGroup, InsertUTC, UpdateUTC " +
                             $"FROM md_asset_Asset WHERE AssetUID = Unhex('{assetUID.ToString("N")}')";
         return(_transaction.Get <ClientModel.Asset>(assetQuery).FirstOrDefault());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error retrieving AssetDetail By Asset Guid for Application from database. {ex}");;
         throw ex;
     }
     finally
     {
     }
 }
예제 #15
0
        public DbUserPreference GetUserPreference(Guid userUID, Guid?preferenceKeyGuid, string preferenceKeyName)
        {
            var isPreferenceExistQuery = string.Format("select *from md_preference_PreferenceUser PU " +
                                                       "inner join md_preference_PreferenceKey PK on PK.PreferenceKeyID = PU.fk_PreferenceKeyID " +
                                                       "and PU.fk_UserUID={0}", userUID.ToStringAndWrapWithUnhex());
            var queryBuilder = new StringBuilder(isPreferenceExistQuery);

            if (!string.IsNullOrEmpty(preferenceKeyName))
            {
                queryBuilder.Append(string.Format(" and PK.PreferenceKeyName = '{0}'", preferenceKeyName));
            }

            if (preferenceKeyGuid.HasValue)
            {
                queryBuilder.Append(string.Format(" and PK.PreferenceKeyUID = {0}",
                                                  preferenceKeyGuid.Value.ToStringAndWrapWithUnhex()));
            }

            isPreferenceExistQuery = queryBuilder.ToString();
            return(transaction.Get <DbUserPreference>(isPreferenceExistQuery).FirstOrDefault());
        }
예제 #16
0
        private Dictionary <string, DbDeviceType> GetDeviceTypeFromSource()
        {
            var deviceTypes   = transactions.Get <DbDeviceType>(Queries.ReadDeviceTypeQuery, null);
            var deviceTypeIDs = new Dictionary <string, DbDeviceType>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var deviceType in deviceTypes)
            {
                deviceTypeIDs.Add(deviceType.TypeName, new DbDeviceType {
                    DeviceTypeID = deviceType.DeviceTypeID, TypeName = deviceType.TypeName, DefaultValueJson = deviceType.DefaultValueJson
                });
            }
            return(deviceTypeIDs);
        }
예제 #17
0
        public List <AssetCustomer> GetAssetCustomerByAssetGuid(Guid assetUid)
        {
            string getCustomersQuery = string.Format(@"SELECT 
											ac.fk_CustomerUID AS CustomerUID,
											c.CustomerName AS CustomerName,
											IFNULL(c.fk_CustomerTypeID,-1) AS CustomerType,
											c1.CustomerUID AS ParentCustomerUID,
											c1.CustomerName AS ParentName,
											IFNULL(c1.fk_CustomerTypeID,-1) AS ParentCustomerType
										FROM
											md_customer_CustomerAsset ac
												LEFT OUTER JOIN
											md_customer_Customer c ON c.CustomerUID = ac.fk_CustomerUID
												LEFT OUTER JOIN
											md_customer_CustomerRelationshipNode crn ON crn.fk_CustomerUID = c.CustomerUID
												LEFT OUTER JOIN
											md_customer_Customer c1 ON c1.CustomerUID = crn.fk_ParentCustomerUID
												AND c1.CustomerUID IN (SELECT 
													acs.fk_CustomerUID
												FROM
													md_customer_CustomerAsset acs
												WHERE
													acs.fk_AssetUID = ac.fk_AssetUID)
										WHERE
											ac.fk_AssetUID = {0};"                                            , assetUid.ToStringWithoutHyphens().WrapWithUnhex());
            var    assetData         = _transaction.Get <AssetCustomer>((getCustomersQuery))?.ToList();
            var    assetCustomer     = assetData?.Select(c => new AssetCustomer
            {
                CustomerName       = c.CustomerName,
                CustomerUID        = c.CustomerUID,
                CustomerType       = (c.CustomerType != "-1") ? ((CustomerType)Enum.Parse(typeof(CustomerType), c.CustomerType)).ToString() : null,
                ParentCustomerUID  = c.ParentCustomerUID ?? null,
                ParentName         = c.ParentCustomerUID.HasValue ? c.ParentName : null,
                ParentCustomerType = c.ParentCustomerUID.HasValue && (c.CustomerType != "-1") ? ((CustomerType)Enum.Parse(typeof(CustomerType), c.CustomerType)).ToString() : null,
            }).ToList();

            return(assetCustomer);
        }
예제 #18
0
        public void GetAccount_ValidAccount_ReturnsResult()
        {
            //Arrange
            var accountUid = Guid.NewGuid();
            var account    = new DbAccount
            {
                CustomerAccountID  = 1,
                CustomerAccountUID = accountUid,
                BSSID                = "BSS01",
                AccountName          = "ACC01",
                NetworkCustomerCode  = "NCC01",
                DealerAccountCode    = "DAC01",
                fk_ParentCustomerUID = Guid.NewGuid(),
                fk_ChildCustomerUID  = Guid.NewGuid(),
                RowUpdatedUTC        = DateTime.UtcNow
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var accountCompareLogic = new CompareLogic(config);

            transaction.Get <DbAccount>(Arg.Any <string>()).Returns(new List <DbAccount> {
                account
            });

            //Act
            var resultData = accountService.GetAccount(accountUid);

            //Arrange
            Assert.NotNull(resultData);
            ComparisonResult compareResult = accountCompareLogic.Compare(account, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
예제 #19
0
        public void GetNullAssetCustomerByAssetGuid()
        {
            //Arrange
            _transaction.Get <AssetCustomer>(Arg.Any <string>()).Returns(x => null);
            //Act
            var assetCustomer = _supportAssetServices.GetAssetCustomerByAssetGuid(new Guid());

            //Assert
            Assert.Null(assetCustomer);
        }
예제 #20
0
        public IActionResult DeleteOnlineQuery(int Id)
        {
            #region FunctionBody
            var onlineQuery = _onlineQueryService.Get(Id);
            if (onlineQuery == null)
            {
                return(StatusCode(400, new ReturnErrorMessage((int)ErrorTypes.Errors.NotFound)));
            }
            bool IsSucceed = _onlineQueryService.Delete(onlineQuery);
            if (!IsSucceed)
            {
                return(StatusCode(500, new ReturnErrorMessage((int)ErrorTypes.Errors.Internal, code: 500)));
            }
            return(Ok(new ReturnMessage()));

            #endregion
        }
예제 #21
0
        public void GetCustomer_ValidCustomer_ReturnsData()
        {
            //Arrange
            var customerUid = Guid.NewGuid();
            var customer    = new DbCustomer
            {
                CustomerID          = 1,
                CustomerUID         = customerUid,
                CustomerName        = "CUS01",
                fk_CustomerTypeID   = 0,
                LastCustomerUTC     = DateTime.UtcNow,
                PrimaryContactEmail = "*****@*****.**",
                FirstName           = "FN01",
                LastName            = "LN01",
                NetworkDealerCode   = "NDC01",
                IsActive            = true
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var accountCompareLogic = new CompareLogic(config);

            transaction.Get <DbCustomer>(Arg.Any <string>()).Returns(new List <DbCustomer> {
                customer
            });

            //Act
            var resultData = customerService.GetCustomer(customerUid);

            //Arrange
            Assert.NotNull(resultData);
            transaction.Received(1)
            .Get <DbCustomer>(Arg.Is <string>(q => q.Contains($"UNHEX('{customerUid.ToString("N")}')")));
            ComparisonResult compareResult = accountCompareLogic.Compare(customer, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
예제 #22
0
        public void TestCreateUserPreference_ValidInput_True()
        {
            //Arrange
            CreateUserPreferenceEvent createUser = new CreateUserPreferenceEvent()
            {
                PreferenceKeyUID  = new Guid("2ccfe195-81ec-4aed-ba31-fc7d794cb75f"),
                UserUID           = new Guid("85293f9c-b713-4e95-a5ed-b36beb2c4aa2"),
                PreferenceKeyName = "Key",
                PreferenceJson    = "Json",
                SchemaVersion     = "v1",
                ActionUTC         = DateTime.UtcNow
            };

            transaction.Get <PreferenceKeyDto>(Arg.Any <string>()).Returns(x => { return(new List <PreferenceKeyDto>()
                {
                    new PreferenceKeyDto()
                    {
                        PreferenceKeyID = 10, PreferenceKeyName = "Key", PreferenceKeyUID = createUser.PreferenceKeyUID.Value
                    }
                }); });

            //Act
            bool?result = preferenceService.CreateUserPreference(createUser);

            //Assert
            Assert.True(result);
            transaction.Received(1).Upsert <DbUserPreference>(Arg.Is <DbUserPreference>(x => x.fk_UserUID == createUser.UserUID));
            transaction.Received(1).Publish(Arg.Is <KafkaMessage>(x => x.Key == createUser.UserUID.ToString()));
            transaction.Received(1).Execute(Arg.Any <List <Action> >());
        }
예제 #23
0
        public void Get_GetAssetDetail()
        {
            //Arrange
            _transaction.Get <AssetDetail>(Arg.Any <string>()).Returns(x => {
                return(new List <AssetDetail>()
                {
                    new AssetDetail()
                    {
                        AssetName = "TestAsset",
                        AssetTypeName = "AS",
                        AssetUID = "a162eb79-0317-11e9-a988-029d68d36a0c",
                        DeviceSerialNumber = "TestDevice",
                        AssetCustomerUIDs = "a162eb79-0317-11e9-a988-029d68d36a0t",
                        DeviceState = "0",
                        DeviceType = "PL640",
                        DeviceUID = "a162eb79-0317-11e9-a988-029d68d36a0r",
                        MakeCode = "DAT",
                        Model = "JJJ",
                        ModelYear = 2019,
                        OwningCustomerUID = "a162eb79-0317-11e9-a988-029d68d36a0y",
                        SerialNumber = "SerialNo1",
                        TimestampOfModification = DateTime.Now,
                    }
                });
            });

            //Act
            var assetServices = (List <AssetDetail>)_assetServices.GetAssetDetail(Guid.NewGuid(), Guid.NewGuid());

            //Assert
            Check(assetServices);

            //Act
            assetServices = (List <AssetDetail>)_assetServices.GetAssetDetail(Guid.NewGuid());
            //Assert
            Check(assetServices);

            //Act
            assetServices = (List <AssetDetail>)_assetServices.GetAssetDetail(null, Guid.NewGuid());
            //Assert
            Check(assetServices);
        }
예제 #24
0
 public IQueryable <LastTransaction> GetTransactions(Func <LastTransaction, bool> predicate = null)
 => _transactions.Get(predicate: predicate);