/// <summary>
        /// Generic REST call for single objects.
        /// </summary>
        /// <typeparam name="E">Object Type.</typeparam>
        /// <typeparam name="T">Collection Object Type.</typeparam>
        /// <param name="rc">REST client.</param>
        /// <param name="rp">REST properties for request.</param>
        /// <returns>Single object response for a REST call.</returns>
        internal ResponseSingle <E> MakeSingleRequest <E, T>(RestClient rc, RestProperties rp) where T : ICollectionType <E, T>, new()
        {
            CheckToken(rc);

            ResponseSingle <E> output  = new ResponseSingle <E>();
            RestRequest        request = RequestBuilder(rp);
            var response = rc.Execute <T>(request);

            try
            {
                output.Data       = response.Data.GetObject.First();
                output.Json       = response.Content;
                output.Xml        = Util.ConvertJson2Xml(response.Content);
                output.StatusCode = (int)response.StatusCode;
                output.Message    = response.StatusDescription;
                output.Header     = Util.BuildHeader(response);
            }
            catch (Exception)
            {
                output.Data       = default(E);
                output.Json       = null;
                output.Xml        = null;
                output.StatusCode = (int)response.StatusCode;
                output.Message    = response.StatusDescription;
                output.Header     = Util.BuildHeader(response);
            }
            return(output);
        }
 //[Route("Create")]
 public async Task<IActionResult> Cast(Vote vote)
 {
     var response = new ResponseSingle<int>();
     _context.Add(vote);
     await _context.SaveChangesAsync();
     //      return NoContent();
     return Ok(response);
 }
示例#3
0
        //[Route("Create")]
        public async Task <IActionResult> Add(Dossier dossier)
        {
            var response = new ResponseSingle <int>();

            _context.Add(dossier);
            await _context.SaveChangesAsync();

            //      return NoContent();
            return(Ok(response));
        }
        //[Route("Create")]
        public async Task <IActionResult> Add(Vote proposition)
        {
            var response = new ResponseSingle <int>();

            _context.Add(proposition);
            await _context.SaveChangesAsync();

            //      return NoContent();
            return(Ok(response));
        }
示例#5
0
        //[Route("Create")]
        public async Task <ResponseSingle <int> > CreateProposition(Proposition proposition)
        {
            _context.Add(proposition);
            proposition.CreationDate = DateTime.Now;
            proposition.UserId       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            await _context.SaveChangesAsync();

            ResponseSingle <int> res = new ResponseSingle <int>();

            res.Data = 1;
            return(res);
        }
示例#6
0
        //[Route("Create")]
        public async Task <IActionResult> Cast(VoteCasted userVote)
        {
            var response      = new ResponseSingle <int>();
            var currentUserID = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            userVote.VotedDate = DateTime.Now;
            userVote.UserId    = currentUserID;

            _context.Add(userVote);
            await _context.SaveChangesAsync();

            return(Ok(response));
        }
示例#7
0
        //[Route("Create")]
        public async Task <IActionResult> Add(Dossier dossier)
        {
            var             response      = new ResponseSingle <int>();
            ClaimsPrincipal currentUser   = this.User;
            var             currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;

            dossier.CreationDate = DateTime.Now;
            dossier.UserId       = currentUserID;

            _context.Add(dossier);

            await _context.SaveChangesAsync();

            return(Ok(response));
        }
        /// <summary>
        /// Request single Contact by refId
        /// </summary>
        /// <param name="refId"></param>
        /// <returns></returns>
        public ResponseSingle<XContactType> GetXContact(string refId)
        {
            ResponseSingle<XContactType> output = new ResponseSingle<XContactType>();

            RestRequest request = new RestRequest("xContacts/{refId}", Method.GET);
            request.AddParameter("refId", refId, ParameterType.UrlSegment);
            request.AddHeader("Accept", "application/json");

            var response = restClient.Execute<XContactCollectionType>(request);

            try
            {
                output.Data = response.Data.xContact.First();
                output.StatusCode = (int)response.StatusCode;
                output.Message = response.StatusDescription;
                output.Header = Util.BuildHeader(response);
            }
            catch (Exception)
            {
                output.Data = null;
                output.StatusCode = (int)response.StatusCode;
                output.Message = response.StatusDescription;
                output.Header = Util.BuildHeader(response);
            }

            return output;
        }
        /// <summary>
        /// Request single Staffs by refId
        /// </summary>
        /// <param name="refId"></param>
        /// <param name="navigationPage"></param>
        /// <param name="navigationPageSize"></param>
        /// <returns></returns>
        public ResponseSingle<XStaffType> GetXStaff(string refId, int? navigationPage, int? navigationPageSize)
        {
            ResponseSingle<XStaffType> output = new ResponseSingle<XStaffType>();

            RestRequest request = new RestRequest("xStaffs/{refId}", Method.GET);
            request.AddParameter("refId", refId, ParameterType.UrlSegment);
            request.AddHeader("Accept", "application/json");
            request.AddHeader("navigationPage", navigationPage.ToString());
            request.AddHeader("navigationPageSize", navigationPageSize.ToString());

            var response = restClient.Execute<XStaffCollectionType>(request);

            try
            {
                output.Data = response.Data.xStaff.First();
                output.StatusCode = (int)response.StatusCode;
                output.Message = response.StatusDescription;
                output.Header = Util.BuildHeader(response);
            }
            catch (Exception)
            {
                output.Data = null;
                output.StatusCode = (int)response.StatusCode;
                output.Message = response.StatusDescription;
                output.Header = Util.BuildHeader(response);
            }

            return output;
        }