Ejemplo n.º 1
0
        public bool AddComment(string username, int productId, string desc)
        {
            Comment comment = new Comment();

            comment.PostingDate = DateTime.Now;
            comment.ProductId = productId;
            comment.TextContent = desc;

            var u = (from d in _db.Users
                     where d.UserName == username
                     select new { d.Id }).SingleOrDefault();

            if (u != null)
            {
                comment.UserId = u.Id;

                _db.Comments.Add(comment);
                _db.SaveChangesAsync();

                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
        public static List<Comment> GetCommentsFromServer(string request, Method method)
        {
            var comments = new List<Comment>();

            var results = Request(request, method);
            try
            {
                JArray ja = JsonConvert.DeserializeObject<JArray>(results);
                foreach (var r in ja)
                {
                    var c = (CommentApi)JsonConvert.DeserializeObject(r.ToString(), typeof(CommentApi));
                    var u = new Comment(c);
                    comments.Add(u);
                }

            }
            catch (Exception ex1)
            {
                Console.WriteLine(ex1.ToString());

                try
                {
                    JObject r = JsonConvert.DeserializeObject<JObject>(results);
                    var c = (CommentApi)JsonConvert.DeserializeObject(r.ToString(), typeof(CommentApi));
                    var u = new Comment(c);
                    comments.Add(u);
                }
                catch (Exception ex2)
                {
                    Console.WriteLine(ex2.ToString());
                }
            }          

            return comments;
        }