/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetTagsResponse response = new GetTagsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Arn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.Arn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Tags", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #2
0
 void Callback(GetTagsResponse response)
 {
     foreach (var tag in response.Tags)
     {
         Debug.WriteLine(tag);
     }
 }
예제 #3
0
        public GetTagsResponse GetTags(GetTagsRequest request)
        {
            var response = new GetTagsResponse();

            try
            {
                if (request.Id <= 0)
                {
                    response.Errors.Add("The Id value is 0 or less");
                }
                else
                {
                    response.Tags = _context.Tag.Where(x => x.Id == request.Id).Select(x => new Tag {
                        Name = x.Name, Id = x.Id
                    }).ToList();
                    return(response);
                }
            }
            catch (Exception msg)
            {
                response.Errors.Add(msg.Message);
            }

            response.Errors.Add("Something went wrong");
            return(response);
        }
예제 #4
0
        public GetTagsResponse GetTags()
        {
            var response = new GetTagsResponse();

            try
            {
                response.Tags = _context.Tag.Select(x => new Tag
                {
                    Id   = x.Id,
                    Name = x.Name,
                }).ToList();
            }
            catch (Exception msg)
            {
                response.Errors.Add(msg.Message);
            }

            return(response);
        }
예제 #5
0
        //GET api/username/Tags
        public GetTagsResponse Get(string username, int?start = 1, int?length = 2)
        {
            GetTagsResponse response = new GetTagsResponse();

            response.Tags   = new List <TagViewModel>();
            response.Start  = start.Value;
            response.Length = length.Value;
            string absolute = RequestContext.Url.Request.RequestUri.AbsoluteUri;
            string nextUrl  = absolute.Split('?')[0];

            nextUrl += "?start=" + (start + length);
            nextUrl += "&length=" + length;

            var query = (from t in _dbContext.Tags
                         join u in _dbContext.Users on t.UserId equals u.Id
                         where u.UserName == username
                         select t);

            query = query.OrderBy(x => x.TagId);
            if (start > 1)
            {
                query = query.Skip(start.Value - 1);
            }

            query = query.Take(length.Value);
            List <Tag> dbTags = query.ToList();

            foreach (var tag in dbTags)
            {
                response.Tags.Add(new TagViewModel()
                {
                    Id   = tag.TagId,
                    Name = tag.Name
                });
            }
            if (response.Tags.Count >= length)
            {
                response.Next = nextUrl;
            }

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetTagsResponse response = new GetTagsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("NextPageToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextPageToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ReturnSize", targetDepth))
                {
                    var unmarshaller = IntUnmarshaller.Instance;
                    response.ReturnSize = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Tags", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("TotalSize", targetDepth))
                {
                    var unmarshaller = IntUnmarshaller.Instance;
                    response.TotalSize = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }