Пример #1
0
        private RequestContract Request()
        {
            RequestContract request = new RequestContract();

            request.Headers = new ParameterContract[] {
                ParameterContract.Create("Ocp-Apim-Subscription-Key", ParameterType.STRING.ToString())
            };
            request.QueryParameters = new ParameterContract[] {
                ParameterContract.Create("filter", ParameterType.STRING.ToString())
            };
            return(request);
        }
        public static RequestContract ConvertToRequestContract(Request request)
        {
            if (request == null)
            {
                return(null);
            }

            RequestContract contractRequest = new RequestContract()
            {
                RequestID = request.RequestID, UserID = request.UserID, FreelancerID = request.FreelancerID, Description = request.Description, StatusID = request.StatusID, StartDate = request.StartDate, EndDate = request.EndDate, AverageCost = request.AverageCost,
            };

            return(contractRequest);
        }
Пример #3
0
        public async Task <Request> Add(RequestContract contract)
        {
            if (contract == null)
            {
                return(null);
            }

            var requestId = Guid.NewGuid();
            var request   = new Request
            {
                Id = requestId,
                ArtObjectCreationDate = contract.ArtObjectCreationDate,
                ArtObjectDescription  = contract.ArtObjectDescription,
                ArtObjectId           = contract.ArtObjectId,
                ArtObjectLatitude     = contract.ArtObjectLatitude,
                ArtObjectLongitude    = contract.ArtObjectLongitude,
                ArtObjectName         = contract.ArtObjectName,
                ArtObjectType         = contract.ArtObjectType,
                Date          = contract.Date,
                Reason        = contract.Reason,
                RequestType   = contract.RequestType,
                RequestStatus = (int)RequestStatus.Active,
                UserId        = contract.UserId
            };

            var photoRequests         = new List <PhotoRequest>();
            var photoRequestContracts = contract.PhotoRequest ?? new List <PhotoRequestContract>();

            foreach (var photoRequestContract in photoRequestContracts)
            {
                var photoRequest = new PhotoRequest
                {
                    Id               = Guid.NewGuid(),
                    RequestId        = requestId,
                    PhotoId          = photoRequestContract.PhotoId,
                    PhotoPath        = photoRequestContract.PhotoPath,
                    PhotoRequestType = photoRequestContract.PhotoRequestType
                };
                photoRequests.Add(photoRequest);
            }

            await context.Request.AddAsync(request);

            await context.PhotoRequest.AddRangeAsync(photoRequests);

            await context.SaveChangesAsync();

            return(await context.Request.FirstOrDefaultAsync(x => x.Id == request.Id));
        }
Пример #4
0
        public void APIOperationBuilder()
        {
            string        name        = "Server API operation";
            RequestMethod method      = RequestMethod.POST;
            string        urlTemplate = "/Get/a/{a}/b/{b}";
            string        description = "an operation created in the operation";

            ParameterContract[] parameters = null;
            RequestContract     request    = null;

            ResponseContract[] responses = null;

            parameters = Parameters();

            APIOperation operation = APIOperation.Create(name, method, urlTemplate, parameters, request, responses, description);

            APIOperationHelper helper = new APIOperationHelper(operation);
        }
Пример #5
0
            /// <summary>
            /// Build an APIOperation from a swagger operation
            /// </summary>
            /// <param name="method"></param>
            /// <returns>An APIOperation</returns>
            public APIOperation BuildOperation(RequestMethod method = RequestMethod.GET)
            {
                if (_operation == null)
                {
                    return(null);
                }

                PrepareParameterLists();

                string name        = _operation.OperationId;
                string description = _operation.Description;
                string urlTemplate = _baseUrl + BuildQueryUrl();

                ParameterContract[] parameters = _pathParameters.Concat(_queryParameters).ToArray();
                ResponseContract[]  responses  = BuildResponses();
                RequestContract     request    = BuildRequest();

                return(APIOperation.Create(name, method, urlTemplate, parameters, request, responses, description));
            }
Пример #6
0
 public RequestContract BuildRequest()
 {
     return(RequestContract.Create(Description, Headers, Queries, Representations));
 }
 public async Task <IActionResult> AddRequest(RequestContract request)
 {
     return(Json(await this.requestService.Add(request)));
 }
Пример #8
0
        /// <summary>
        /// Get Access Codes from the DeSciL Mturk Service
        /// </summary>
        /// <returns>Service response as Json</returns>
        public string GetCodes()
        {
            var contract = new RequestContract
            {
                Operation = "GetCodes",
                ServiceKey = _serviceKey,
                ProjectCode = _projectCode
            };

            string json =  JsonConvert.SerializeObject(contract);
            string result = Post(json);
            var response = JsonConvert.DeserializeObject<ResponseContract>(result);
            var codes = response.Codes;

            foreach(Code sc in response.Codes)
            {
                // Only add unlocked codes
                if (sc.Status == 0)
                {
                    var code = _db.Codes.FirstOrDefault(x => x.AccessCode == sc.AccessCode);
                    if (code == null)
                    {
                        var lc = new Segreg.Models.Code
                        {
                            AccessCode = sc.AccessCode,
                            ExitCode = sc.ExitCode,
                            IsUsed = false
                        };
                        _db.Add(lc);
                    }
                }
            }

            // Save codes from WebService to local store
            _db.Save();

            return result;
        }