Exemplo n.º 1
0
        public HttpResponseMessage Post([FromBody] string feed)
        {
            if (string.IsNullOrWhiteSpace(feed))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var f = feedRepository.AddFeed(new Feed()
            {
                Body = feed
            });
            var response = Request.CreateResponse(HttpStatusCode.Created);

            response.Headers.Location = new Uri(Url.Link("GetFeedById", new { id = f.Id }));
            return(response);
        }
Exemplo n.º 2
0
        public async Task <object> AddFeed([FromBody] FeedViewModel webFeedViewModel)
        {
            try
            {
                bool   result = true;
                string error  = string.Empty;

                Feed feed = new Feed();

                var            id        = webFeedViewModel.UserId;
                DateTimeOffset timestamp = DateTimeOffset.Now;
                try
                {
                    feed = _feedRepository.AddFeed(id, webFeedViewModel.Data, false, timestamp, webFeedViewModel.DepartmentId);

                    byte[] byteArray     = Convert.FromBase64String(webFeedViewModel.Data);
                    string decodedString = Encoding.UTF8.GetString(byteArray);
                    feed.Data = decodedString;
                }
                catch (Exception ex)
                {
                    result = false;
                    error  = ex.Message;
                }

                return(new SingleResponse <Feed>
                {
                    Message = "Added to feed successfully",
                    DidError = false,
                    ErrorMessage = string.Empty,
                    Token = string.Empty,
                    Model = feed
                });
            }
            catch (Exception ex)
            {
                return(new SingleResponse <Feed>
                {
                    Message = ex.InnerException.ToString(),
                    DidError = true,
                    ErrorMessage = ex.Message,
                    Token = string.Empty,
                    Model = null
                });
            }
        }