Example #1
0
        public static async Task <RO <CardList> > CardList(CurrentClientData currentClient)
        {
            var ro = new RO <CardList> {
                ReturnCode = 0, Message = string.Empty
            };

            _db.GetCollection <DBCard>("cards");
            var clientList = _db.GetCollection <DBClient>("clients").Include(x => x.Cards);

            IEnumerable <DBClient> clients = null;
            DBClient client = null;

            clients = currentClient.InstallationID != "NA" ?
                      clientList.Find(a => a.InstallationID.Equals(currentClient.InstallationID) && a.Id.Equals(int.Parse(currentClient.CustomerKey))) :
                      clientList.Find(a => a.Id.Equals(int.Parse(currentClient.CustomerKey)));

            if (clients != null)
            {
                client = clients.FirstOrDefault();
            }

            if (client != null)
            {
                var cardsList = client.Cards.Where(c => c.Deleted).Select(c => new BossIDWS.Vendor.REST.ReturnObjects.Card
                {
                    rfid   = c.RFID,
                    status = "D"
                }).Concat(client.Cards.Where(c => c.Blocked && c.Deleted == false).Select(c => new BossIDWS.Vendor.REST.ReturnObjects.Card
                {
                    rfid   = c.RFID,
                    status = "B"
                })).Concat(client.Cards.Where(c => c.Blocked == false && c.Deleted == false).Select(c => new BossIDWS.Vendor.REST.ReturnObjects.Card
                {
                    rfid   = c.RFID,
                    status = "A"
                })).ToList();

                //var cards = new CardList { Cards = cardsList };
                var cards = new CardList();
                ro.ReturnValue = cards;
            }

            return(await Task.FromResult(ro));
        }
Example #2
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));
        }