예제 #1
0
        public async Task <RO <Client> > CustomerNewHousehold([FromBody] HouseHoldClientData client)
        {
            var ro = new RO <Client>();

            if (ModelState.IsValid)
            {
                                #if SESAM
                VendorInterface vendor = new VendorInterface();
                ro = await vendor.AddNewClient(client);
                                #else
                var result = await VendorDL.AddNewClient(client);

                if (result != null)
                {
                    ro.ReturnCode  = 0;
                    ro.ReturnValue = result;
                }
                else
                {
                    ro.ReturnCode = -1;
                }
                                #endif
            }
            else
            {
                var message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage));
                ro.ReturnCode = -100;
                ro.Message    = $"Bad request - CustomerNewHousehold - Incorrect parameters: {message}";
            }
            return(ro);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public async Task <BossIDWS.Vendor.REST.ReturnObjects.RO <Client> > AddNewClient(HouseHoldClientData client)
        {
            var roc = new BossIDWS.Vendor.REST.ReturnObjects.RO <Client>(100, "Obsolete", new Client());

            return(await Task.FromResult(roc));
        }
예제 #3
0
        private static void InitializeTestData()
        {
            /**************************************************
            *  Testparameters spesific to current test
            **************************************************/

            Type            = TestType.REST;
            _installationID = "123";

            //Add accesspoints - at least 3
            AvailableAccessPoints = new List <AccessPoint>();

            var ap1 = new AccessPoint {
                accesspointid = "1718", tag = "", name = "1"
            };

            AvailableAccessPoints.Add(ap1);

            var ap2 = new AccessPoint {
                accesspointid = "1719", tag = "", name = "2"
            };

            AvailableAccessPoints.Add(ap2);

            var ap3 = new AccessPoint {
                accesspointid = "1720", tag = "", name = "3"
            };

            AvailableAccessPoints.Add(ap3);

            /**************************************************
            *  Generic testparameters - no need to touch.....
            **************************************************/
            _allAccessPoints = new AccessPointData {
                InstallationID = InstallationID, Type = AccessPointData.AccessPointType.ALL
            };
            _accessPointsByID = new AccessPointData {
                InstallationID = InstallationID, Type = AccessPointData.AccessPointType.ID, AccessPoint = ap1.accesspointid
            };
            _accessPointsByName = new AccessPointData {
                InstallationID = InstallationID, Type = AccessPointData.AccessPointType.NAME, AccessPoint = ap2.name
            };
            _accessPointsByTag = new AccessPointData {
                InstallationID = InstallationID, Type = AccessPointData.AccessPointType.TAG, AccessPoint = ap3.tag
            };
            _apOutOfOrder = new AccessPointOutOfOrderData {
                InstallationID = TestSetup.InstallationID, AccessPoint = ap1.name, Message = "Out of Order", Type = AccessPointData.AccessPointType.NAME
            };

            if (Type == TestType.LiteDB)
            {
                AvailableAccessPoints.Add(VendorDL.GetRandomAccessPoint());
                AvailableAccessPoints.Add(VendorDL.GetRandomAccessPoint());
                AvailableAccessPoints.Add(VendorDL.GetRandomAccessPoint());
            }

            _availableCards = new Stack <string>();

            // Generate RFID cards
            for (var i = 0; i < 50; i++)
            {
                _availableCards.Push(Utils.GetRandomHexString());
            }

            HouseHoldClient = new HouseHoldClientData
            {
                Customerguid   = Guid.NewGuid().ToString(),
                Customerid     = Utils.GetRandomNumber(1001, 1000000).ToString(),
                Description    = "sample client description",
                Primary        = AvailableAccessPoints[0].accesspointid,
                Secondary1     = AvailableAccessPoints[1].accesspointid,
                Propertyunit   = "Propertyunitstring",
                Streetaddress  = "Customer address",
                RFID           = _availableCards.Pop() + ";" + _availableCards.Pop(),
                InstallationID = InstallationID
            };

            HouseHoldClient2 = new HouseHoldClientData
            {
                Customerguid   = Guid.NewGuid().ToString(),
                Customerid     = Utils.GetRandomNumber(1001, 1000000).ToString(),
                Description    = "testclient - to be deleted during test",
                Primary        = AvailableAccessPoints[0].accesspointid,
                Secondary1     = AvailableAccessPoints[1].accesspointid,
                Propertyunit   = "Propertyunitstring",
                Streetaddress  = "Customer address",
                RFID           = _availableCards.Pop() + ";" + _availableCards.Pop(),
                InstallationID = InstallationID
            };

            CommercialClient = new CommercialClientData
            {
                Name           = "Commercial name",
                Customerguid   = Guid.NewGuid().ToString(),
                Customerid     = new Random().Next(1001, 1000000).ToString(),
                Description    = "sample client description",
                Primary        = AvailableAccessPoints[0].accesspointid,
                Secondary1     = AvailableAccessPoints[1].accesspointid,
                Propertyunit   = "Propertyunitstring",
                Streetaddress  = "Customer address",
                RFID           = _availableCards.Pop() + ";" + _availableCards.Pop(),
                InstallationID = InstallationID
            };

            RequestAllEvents = new EventsData
            {
                Customerkey    = "ALL",
                FromDate       = DateTime.Now.AddDays(-100),
                ToDate         = DateTime.Now,
                InstallationID = InstallationID
            };

            if (Client1 == null)
            {
                var c1 = JsonConvert.DeserializeObject <Client>(Utils.GetSetting("Client1"));
                if (c1 != null)
                {
                    Client1 = c1;
                }

                var c2 = JsonConvert.DeserializeObject <Client>(Utils.GetSetting("Client2"));
                if (c2 != null)
                {
                    Client2 = c2;
                }
            }
        }
예제 #4
0
        public static async Task <Client> AddNewClient(HouseHoldClientData client)
        {
            // Get card collection
            var allCards = _db.GetCollection <DBCard>("cards");

            // Get customer collection
            var allClients = _db.GetCollection <DBClient>("clients");

            // Get accesspoint collection
            var allAccesspoints = _db.GetCollection <DBAccessPoint>("accesspoints");

            // Get accesspointdetail collection
            var allAccesspointDetails = _db.GetCollection <DBAccessPointDetail>("accesspointDetails");

            var cards            = client.RFID.Split(';').Select(rfid => allCards.FindOne(x => x.RFID.Equals(rfid))).ToList();
            var primaryPoints    = client.Primary.Split(';').Select(nameOfPoint => allAccesspoints.FindOne(a => a.name.Equals(nameOfPoint))).ToList();
            var secondary1Points = client.Secondary1.Split(';').Select(nameOfPoint => allAccesspoints.FindOne(a => a.name.Equals(nameOfPoint))).ToList();
            var secondary2Points = client.Secondary2.Split(';').Select(nameOfPoint => allAccesspoints.FindOne(a => a.name.Equals(nameOfPoint))).ToList();

            // Insert new client and cards assigned to client
            var dbclient = new DBClient
            {
                InstallationID         = client.InstallationID,
                ClientType             = "H",
                Customerid             = client.Customerid,
                Customerguid           = client.Customerguid,
                Propertyunit           = client.Propertyunit,
                Streetaddress          = client.Streetaddress,
                Description            = client.Description,
                Primary                = client.Primary,
                Secondary1             = client.Secondary1,
                Secondary2             = client.Secondary2,
                Cards                  = cards,
                PrimaryAccessPoints    = primaryPoints,
                Secondary1AccessPoints = secondary1Points,
                Secondary2AccessPoints = secondary2Points
            };

            allClients.Insert(dbclient);

            // Verify
            var fullClient = allClients.Include(x => x.Cards).Include(x => x.PrimaryAccessPoints).Include(x => x.Secondary1AccessPoints).Include(x => x.Secondary2AccessPoints).Find(x => x.Customerid.Equals(client.Customerid)).FirstOrDefault();

            var bossIDCustomer = new Client();

            if (fullClient != null)
            {
                var accesspoints =
                    fullClient.PrimaryAccessPoints.Concat(fullClient.Secondary1AccessPoints)
                    .Concat(fullClient.Secondary2AccessPoints)
                    .Select(x => new BossIDWS.Vendor.REST.ReturnObjects.AccessPoint
                {
                    name = x.name
                }).ToList();

                bossIDCustomer = new Client
                {
                    customerkey    = fullClient.Id.ToString(),
                    AccessPoints   = accesspoints,
                    installationid = client.InstallationID
                };
            }

            return(await Task.FromResult(bossIDCustomer));
        }