public CardDataObject(CardDataObject card)
 {
     id       = "";
     cardName = "";
     cardCode = card.cardCode;
     folder   = "";
 }
        public IHttpActionResult DeleteCard(string externalId, string cardExternalId)
        {
            try
            {
                UsersDataObject userDO = dataAccess.GetUserByExternalID(externalId);
                if (userDO == null)
                {
                    return(NotFound());
                }

                CardDataObject cardDO = userDO.Cards.Where(x => x.ExternalId == cardExternalId).FirstOrDefault();
                if (cardDO == null)
                {
                    return(NotFound());
                }

                dataAccess.DeleteCardByExternalID(cardExternalId);

                return(new NoContentActionResult(Request.CreateResponse()));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult PostCards(string externalId, [FromBody] CardsModel model)
        {
            try
            {
                UsersDataObject userDO = dataAccess.GetUserByExternalID(externalId);
                if (userDO == null)
                {
                    return(NotFound());
                }

                CardDataObject c = modelFactory.Parse(model);

                dataAccess.InsertUserCard(c.ExternalId, c.BadgeNumber, c.IsActive, c.PIN, userDO.Id);

                userDO = dataAccess.GetUserByExternalID(externalId);
                CardDataObject cardDO = userDO.Cards.Where(x => x.ExternalId == model.ExternalId).FirstOrDefault();
                if (cardDO == null)
                {
                    return(NotFound());
                }

                return(CreatedAtRoute <CardsModel>("Cards", new { externalId = externalId, cardExternalId = cardDO.ExternalId }, modelFactory.Create(externalId, cardDO)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #4
0
        public CardDataObject Parse(CardsModel cardModel)
        {
            CardDataObject obj = new CardDataObject
            {
                ExternalId   = cardModel.ExternalId,
                BadgeNumber  = cardModel.BadgeNumber,
                IsActive     = cardModel.IsActive,
                PIN          = cardModel.PIN,
                FacilityCode = cardModel.FacilityCode,
                Priority     = cardModel.Priority,
                IsBypass     = cardModel.IsBypass
            };

            return(obj);
        }
Beispiel #5
0
        public CardsModel Create(string externalId, CardDataObject cardDO)
        {
            CardsModel model = new CardsModel
            {
                Url          = urlHelper.Link("Card", new { externalId = externalId, cardExternalId = cardDO.ExternalId }),
                ExternalId   = cardDO.ExternalId,
                BadgeNumber  = cardDO.BadgeNumber,
                IsActive     = cardDO.IsActive,
                FacilityCode = cardDO.FacilityCode,
                IsBypass     = cardDO.IsBypass,
                Priority     = cardDO.Priority
            };

            return(model);
        }
    public void AddCard()
    {
        // Check if we are at the max card limit
        if (listItemInstances.Count >= maxCards - 1)
        {
            cardLimitEvent.Invoke();
        }
        else
        {
            nonCardLimitEvent.Invoke();
        }
        if (listItemInstances.Count >= maxCards)
        {
            return;
        }


        // Spawn Prefab & set data
        CardDataObject card = new CardDataObject(regionNames[regionIndex.value]);

        if (regionIndex2.value != 13)
        {
            card.cardCode += " ++" + regionNames[regionIndex2.value];
        }
        card.SetName();
        card.GenerateID();

        GameObject newItem = Instantiate(listItemPrefab, content);
        ListItem   it      = newItem.GetComponent <ListItem>();

        it.cardData       = card;
        it.listManager    = this;
        it.listOrderIndex = activeSaveData.cardData.Count;

        // Add to spawned instances
        listItemInstances.Add(it);

        // Clear actives
        activeItem     = null;
        activeDragging = null;
        activeHovering = null;

        // Set as active item if none is active
        StartCoroutine(SetAsActive(it));
        activeSaveData.cardData.Add(card);
    }
Beispiel #7
0
 public void UpdateCard(CardDataObject cardDO)
 {
     using (SqlConnection conn = this.GetConnection())
     {
         conn.Open();
         using (SqlCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = "UPDATE [dbo].[Card] SET BadgeNumber = @BadgeNumber, Priority = @Priority, IsBypass = @IsBypass, IsActive = @IsActive, PIN = @PIN, FacilityCode = @FacilityCode WHERE ExternalID1 = @ExternalID1";
             cmd.Parameters.AddWithValue("@BadgeNumber", cardDO.BadgeNumber);
             cmd.Parameters.AddWithValue("@Priority", cardDO.Priority);
             cmd.Parameters.AddWithValue("@IsBypass", cardDO.IsBypass);
             cmd.Parameters.AddWithValue("@IsActive", cardDO.IsActive);
             cmd.Parameters.AddWithValue("@PIN", cardDO.PIN);
             cmd.Parameters.AddWithValue("@FacilityCode", cardDO.FacilityCode);
             cmd.Parameters.AddWithValue("@ExternalID1", cardDO.ExternalId);
             cmd.ExecuteNonQuery();
         }
     }
 }
        public IHttpActionResult PatchCard(string externalId, string cardExternalId, [FromBody] JsonPatchDocument <CardsModel> cardsModelPatchDoc)
        {
            try
            {
                UsersDataObject userDO = dataAccess.GetUserByExternalID(externalId);
                if (userDO == null)
                {
                    return(NotFound());
                }

                CardDataObject cardDO = userDO.Cards.Where(x => x.ExternalId == cardExternalId).FirstOrDefault();
                if (cardDO == null)
                {
                    return(NotFound());
                }

                CardsModel m = modelFactory.Create(externalId, cardDO);

                if (cardsModelPatchDoc.Operations.Any(x => x.OperationType != Marvin.JsonPatch.Operations.OperationType.Replace ||
                                                      !(x.path == "badgenumber" || x.path == "isactive" || x.path == "pin" || x.path == "priority" || x.path == "isbypass" || x.path == "facilitycode") ||
                                                      String.IsNullOrEmpty(x.value.ToString())))
                {
                    return(BadRequest("Patch only support op:replace path:badgenumber|isactive|pin value:notnullorempty"));
                }

                cardsModelPatchDoc.ApplyTo(m);

                cardDO = modelFactory.Parse(m);

                dataAccess.UpdateCard(cardDO);

                return(Ok(m));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult GetCards(string externalId, string cardExternalId)
        {
            try
            {
                UsersDataObject userDO = dataAccess.GetUserByExternalID(externalId);
                if (userDO == null)
                {
                    return(NotFound());
                }

                CardDataObject cardDO = userDO.Cards.Where(x => x.ExternalId == cardExternalId).FirstOrDefault();
                if (cardDO == null)
                {
                    return(NotFound());
                }

                return(Ok(modelFactory.Create(externalId, cardDO)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #10
0
        private UsersDataObject fillUserDataObj(SqlCommand command)
        {
            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            da.Fill(ds);

            if (ds.Tables[0].Rows.Count == 0) return null;

            var user = new UsersDataObject();

            DataRow userRow = ds.Tables[0].Rows[0];
            user.Id = Int32.Parse(userRow["Id"].ToString());
            user.ExternalID = userRow["ExternalID"].ToString();
            user.Name = userRow["Name"].ToString();
            user.DevicePassword = userRow["DevicePassword"].ToString();
            user.Password = userRow["Password"].ToString();
            user.ImageData = (byte[])(userRow["UserImage"] == DBNull.Value ? null : userRow["UserImage"]);
            user.IsAdministrator = userRow["IsAdministrator"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsAdministrator"].ToString());
            user.IsDeviceAdministrator = userRow["IsDeviceAdministrator"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsDeviceAdministrator"].ToString());
            user.UpdatedAt = userRow["UpdatedAt"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(userRow["UpdatedAt"]);
            user.IsActive = userRow["IsActive"] == DBNull.Value ? false : Convert.ToBoolean(userRow["IsActive"].ToString());
            user.Fingers = new ObservableCollection<FingerDataObject>();

            if (ds.Tables.Count > 1)
            {
                foreach (DataRow fingerRow in ds.Tables[1].Rows)
                {
                    var finger = new FingerDataObject();
                    int fingerInd = Int32.Parse(fingerRow["FingerIndex"].ToString());
                    finger.FingerIndex = FingerDataObject.FingerCodeDescriptions[(FingerDataObject.FingerCode)fingerInd];  // fingerRow["FingerIndex"].ToString();
                    finger.Templates = new ObservableCollection<TemplateObject>();
                    foreach (DataRow templateRow in ds.Tables[2].Rows)
                    {
                        int templateFingerInd = Int32.Parse(templateRow["FingerIndex"].ToString());

                        if (templateFingerInd == fingerInd)
                        {
                            var template = new TemplateObject();
                            template.Id = templateRow["Id"] == DBNull.Value ? 0 : Int32.Parse(templateRow["Id"].ToString());
                            template.QualityScore = Int32.Parse(templateRow["QualityScore"].ToString());
                            template.Checksum = Int64.Parse(templateRow["Checksum"].ToString());
                            template.FingerIndex = templateFingerInd;
                            template.UserID = Int32.Parse(templateRow["UserId"].ToString());
                            template.Data = (byte[])(templateRow["Data"] == DBNull.Value ? null : templateRow["Data"]);
                            template.UpdatedAt = templateRow["UpdatedAt"] == DBNull.Value ? new DateTime(1970, 1, 1) : Convert.ToDateTime(userRow["UpdatedAt"]);

                            finger.Templates.Add(template);
                        }
                    }
                    user.Fingers.Add(finger);
                }
                user.FingersCount = user.Fingers.Count;
            }

            user.Cards = new ObservableCollection<CardDataObject>();
            if (ds.Tables.Count > 3)
            {
                foreach (DataRow cardRow in ds.Tables[3].Rows)
                {
                    var card = new CardDataObject();
                    card.Id = cardRow["Id"].ToString();
                    card.ExternalId = cardRow["ExternalId1"].ToString();
                    card.IsActive = cardRow["IsActive"] == DBNull.Value ? false : Convert.ToBoolean(cardRow["IsActive"].ToString());
                    card.IsBypass = cardRow["IsBypass"] == DBNull.Value ? false : Convert.ToBoolean(cardRow["IsBypass"].ToString());
                    card.BadgeNumber = cardRow["BadgeNumber"].ToString();
                    card.Priority = cardRow["Priority"] == DBNull.Value ? 0 : Int32.Parse(cardRow["Priority"].ToString());
                    card.FacilityCode = cardRow["FacilityCode"] == DBNull.Value ? 0 : Int64.Parse(cardRow["FacilityCode"].ToString());
                    card.PIN = cardRow["PIN"].ToString();
                    user.Cards.Add(card);
                }
                user.CardsCount = user.Cards.Count;
            }

            user.Locations = new ObservableCollection<LocationDataObject>();
            if (ds.Tables.Count > 4)
                foreach (DataRow locationRow in ds.Tables[4].Rows)
                {
                    var location = new LocationDataObject();
                    location.Id = locationRow["Id"].ToString();
                    location.Location = locationRow["Location"].ToString();
                    user.Locations.Add(location);
                }
 

            user.Properties = new ObservableCollection<PropertyDataObject>();
            if (ds.Tables.Count > 5)
                foreach (DataRow propertyRow in ds.Tables[5].Rows)
                {
                    var Property = new PropertyDataObject();
                    Property.ID = propertyRow["User_id"].ToString();
                    Property.Property = new KeyValuePair<string, string>(propertyRow["propertyName"].ToString(), propertyRow["propertyValue"].ToString());
                    user.Properties.Add(Property);
                }

            return user;
        }