コード例 #1
0
        public async Task <IActionResult> Post([FromBody] RewardRegion region)
        {
            if (region == null)
            {
                // return HTTP 400 badrequest as something is wrong
                return(BadRequest("Region information formatted incorrectly."));
            }

            var rgn = new RewardRegion()
            {
                Region_name = region.Region_name,
                Projects    = region.Projects
            };

            // Save the new user to the DB
            var result = await _rewardRepository.CreateRegion(rgn);

            if (result == 1)
            {
                // return HTTP 201 Created with country object in body of return and a 'location' header with URL of newly created object
                return(CreatedAtAction("Get", new { region_name = region.Region_name }, rgn));
            }
            else if (result == -10)
            {
                // return HTTP 409 Conflict as user already exists in DB
                return(Conflict("Region with name '" + region.Region_name + "' already exists.  Cannot create a duplicate."));
            }
            else
            {
                // return HTTP 400 badrequest as something is wrong
                return(BadRequest("An internal error occurred.  Please contact the system administrator."));
            }
        }
コード例 #2
0
        public async Task <int> AddProject(string region_name, Project project)
        {
            using (var context = _dbConnection.Context())
            {
                try
                {
                    RewardRegion region = await context.LoadAsync <RewardRegion>(region_name);

                    if (region != null)
                    {
                        region.Projects.Add(project);
                        await context.SaveAsync(region);

                        return(1);
                    }
                    else
                    {
                        // 404 - Country with specified name doesn't exist
                        return(-9);
                    }
                }
                catch (AmazonServiceException ase)
                {
                    Debug.WriteLine("Could not complete operation");
                    Debug.WriteLine("Error Message:  " + ase.Message);
                    Debug.WriteLine("HTTP Status:    " + ase.StatusCode);
                    Debug.WriteLine("AWS Error Code: " + ase.ErrorCode);
                    Debug.WriteLine("Error Type:     " + ase.ErrorType);
                    Debug.WriteLine("Request ID:     " + ase.RequestId);
                    return(-1);
                }
                catch (AmazonClientException ace)
                {
                    Debug.WriteLine("Internal error occurred communicating with DynamoDB");
                    Debug.WriteLine("Error Message:  " + ace.Message);
                    return(-1);
                }
                catch (NullReferenceException e)
                {
                    Debug.WriteLine("Context obj for DynamoDB set to null");
                    Debug.WriteLine("Error Message:  " + e.Message);
                    Debug.WriteLine("Inner Exception:  " + e.InnerException);
                    return(-1);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Internal error occurred communicating with DynamoDB");
                    Debug.WriteLine("Error Message:  " + e.Message);
                    Debug.WriteLine("Inner Exception:  " + e.InnerException);
                    return(-1);
                }
            }
        }
コード例 #3
0
        public async Task <int> CreateRegion(RewardRegion region)
        {
            using (var context = _dbConnection.Context())
            {
                try
                {
                    var exits = await context.LoadAsync <RewardRegion>(region.Region_name);

                    if (exits != null)
                    {
                        return(-10);
                    }
                    else
                    {
                        await context.SaveAsync(region);

                        return(1);
                    }
                }
                catch (AmazonServiceException ase)
                {
                    Debug.WriteLine("Could not complete operation");
                    Debug.WriteLine("Error Message:  " + ase.Message);
                    Debug.WriteLine("HTTP Status:    " + ase.StatusCode);
                    Debug.WriteLine("AWS Error Code: " + ase.ErrorCode);
                    Debug.WriteLine("Error Type:     " + ase.ErrorType);
                    Debug.WriteLine("Request ID:     " + ase.RequestId);
                    return(-1);
                }
                catch (AmazonClientException ace)
                {
                    Debug.WriteLine("Internal error occurred communicating with DynamoDB");
                    Debug.WriteLine("Error Message:  " + ace.Message);
                    return(-1);
                }
                catch (NullReferenceException e)
                {
                    Debug.WriteLine("Context obj for DynamoDB set to null");
                    Debug.WriteLine("Error Message:  " + e.Message);
                    Debug.WriteLine("Inner Exception:  " + e.InnerException);
                    return(-1);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Internal error occurred communicating with DynamoDB");
                    Debug.WriteLine("Error Message:  " + e.Message);
                    Debug.WriteLine("Inner Exception:  " + e.InnerException);
                    return(-1);
                }
            }
        }