Exemplo n.º 1
0
        public IEnumerable <Organization> GetAll()
        {
            List <Organization> returnValue = new List <Organization>();

            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                ScanRequest request = CreateScanRequest();

                ScanResponse response = client.Scan(request);

                if (response.Items == null || response.Items.Any() == false)
                {
                    string errorMessage = string.Format(ErrorMessages.MisingResponseItem, "Get Organization");
                    throw new MissingFieldException(errorMessage);
                }

                foreach (Dictionary <string, AttributeValue> item in response.Items)
                {
                    Organization organization = DynamoUtilities.GetItemFromAttributeStore <Organization>(item);

                    returnValue.Add(organization);
                }
                return(returnValue);
            }
        }
Exemplo n.º 2
0
        public DataInfo Get(DataInfo item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                ScanRequest request = CreateScanRequest(item.DataId);
                if (request.ScanFilter.Count == 0)
                {
                    throw new InvalidOperationException(ErrorMessages.NoSearchCriteria);
                }

                ScanResponse response = client.Scan(request);

                if (response.Items == null)
                {
                    string errorMessage = string.Format(ErrorMessages.MisingResponseItem, "Get Data Info");
                    throw new MissingFieldException(errorMessage);
                }

                Dictionary <string, AttributeValue> userData = response.Items[0];

                var returnValue = DynamoUtilities.GetItemFromAttributeStore <DataInfo>(userData);

                return(returnValue);
            }
        }
Exemplo n.º 3
0
        public UserInfo Add(UserInfo item)
        {
            if (item.Id == Guid.Empty)
            {
                item.Id = Guid.NewGuid();
            }

            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                PutItemRequest request = CreatePutItemRequest(item);

                try
                {
                    client.PutItem(request);

                    return(item);
                }
                catch (AmazonDynamoDBException ex)
                {
                    throw new MissingFieldException(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        public void Remove(DataInfo item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                DeleteItemRequest request = CreateDeleteItemRequest(item);

                client.DeleteItem(request);
            }
        }
Exemplo n.º 5
0
        public void Remove(Organization item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                DeleteItemRequest request = CreateDeleteItemRequest(item.OrganizationId);

                client.DeleteItem(request);
            }
        }
Exemplo n.º 6
0
        public Guid Add(Organization item)
        {
            if (item.OrganizationId == Guid.Empty)
            {
                item.OrganizationId = Guid.NewGuid();
            }

            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                PutItemRequest request = CreatePutItemRequest(item);

                client.PutItem(request);
            }

            return(item.OrganizationId);
        }
Exemplo n.º 7
0
        public DataInfo Add(DataInfo item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                PutItemRequest request = CreatePutItemRequest(item);

                try
                {
                    client.PutItem(request);

                    return(item);
                }
                catch (AmazonDynamoDBException ex)
                {
                    throw new MissingFieldException(ex.Message);
                }
            }
        }
Exemplo n.º 8
0
        public Organization Get(Guid id)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                GetItemRequest request = CreateGetItemRequest(id);

                GetItemResponse response = client.GetItem(request);

                if (response.Item == null)
                {
                    string errorMessage = string.Format(ErrorMessages.MisingResponseItem, "Get Organization");
                    throw new MissingFieldException(errorMessage);
                }

                Organization returnValue = DynamoUtilities.GetItemFromAttributeStore <Organization>(response.Item);

                return(returnValue);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// This method will use whatever information is supplied to scan the table
        /// supported fields are:
        /// CustomerId
        /// UserName
        /// Password(Hash)
        /// EmailAddress
        /// </summary>
        /// <param name="searchCriteria"></param>
        /// <returns></returns>
        public IEnumerable <UserInfo> Search(UserInfo searchCriteria)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                ScanRequest request = CreateScanRequest(searchCriteria);
                if (request.ScanFilter.Count == 0)
                {
                    throw new InvalidOperationException(ErrorMessages.NoSearchCriteria);
                }

                List <UserInfo> returnValue = new List <UserInfo>();

                try
                {
                    ScanResponse response = client.Scan(request);

                    if (response.Items == null)
                    {
                        string errorMessage = string.Format(ErrorMessages.MisingResponseItem, "Search User");
                        throw new MissingFieldException(errorMessage);
                    }

                    foreach (Dictionary <string, AttributeValue> item in response.Items)
                    {
                        UserInfo user = DynamoUtilities.GetItemFromAttributeStore <UserInfo>(item);
                        returnValue.Add(user);
                    }
                }
                catch (AmazonDynamoDBException ex)
                {
                    //expected exception, 404
                }

                return(returnValue);
            }

            throw new NotImplementedException();
        }