public static JsonComment SaveComment(string id, string author, string email, string website, string cont)
        {
            // There really needs to be validation here so people aren't just posting willy-nilly
            // as anyone they want.

            if (!Security.IsAuthorizedTo(Rights.CreateComments))
            {
                throw new System.Security.SecurityException("Can not create comment");
            }


            var gId = new Guid(id);
            var jc  = new JsonComment();

            foreach (var p in Post.Posts.ToArray())
            {
                foreach (var c in p.Comments.Where(c => c.Id == gId).ToArray())
                {
                    c.Author  = author;
                    c.Email   = email;
                    c.Website = new Uri(website);
                    c.Content = cont;

                    // need to mark post as "dirty"
                    p.DateModified = DateTime.Now;
                    p.Save();

                    return(JsonComments.GetComment(gId));
                }
            }

            return(jc);
        }
        public async Task <JsonResult> AddComment([FromBody] JsonComment data)
        {
            ViewComments viewComment;

            if (data.Text.Trim() != "")
            {
                User    user    = _context.User.FirstOrDefault(s => s.Id == Int32.Parse(User.Identity.Name));
                Comment comment = new Comment {
                    Text   = System.Web.HttpUtility.HtmlEncode(data.Text),
                    UserId = Int32.Parse(User.Identity.Name),
                    PostId = data.PostId,
                    Date   = DateTime.Now
                };
                _context.Add(comment);
                await _context.SaveChangesAsync();

                viewComment = new ViewComments {
                    Id       = User.Identity.Name,
                    UserName = user.Username,
                    Avatar   = user.Avatar,
                    Date     = comment.Date.ToString("dd.MM.yyyy hh:mm tt"),
                    Text     = comment.Text,
                    Error    = null
                };
            }
            else
            {
                viewComment = new ViewComments {
                    Error = "You did not enter a comment"
                };
            }
            return(Json(viewComment));
        }
Beispiel #3
0
        public void Map_Null_ReturnsNull()
        {
            var mapper = CreateMapper();

            JsonComment result = mapper.Map(null);

            Check.That(result).IsNull();
        }
        public JsonResult CommentOnDiscussion(string comm)
        {
            JsonComment c = new JsonComment();

            c.IsCommentOK = false;
            LoginDetails loginDetails = (LoginDetails)Session["loginDetails"];

            if (loginDetails == null)
            {
                return(this.Json(c));
            }
            if (Session["discussionSelected"] == null)
            {
                return(this.Json(c));
            }
            if (Session["selectedClass"] == null)
            {
                return(this.Json(c));
            }
            int user = (int)Session["user"];

            if (user != 1)
            {
                return(this.Json(c));
            }
            if (comm == null)
            {
                return(this.Json(c));
            }

            int did = (int)Session["discussionSelected"];
            int cid = (int)Session["selectedClass"];
            DiscussionComment comment = new DiscussionComment();

            comment.Body = comm;
            comment.Time = DateTime.Now.ToString();
            Teacher t = data.GetInstructor(cid);

            comment.FullName = t.FirstName + " " + t.LastName;
            comment.Username = t.Username;
            data.AddComment(did, comment);

            c.IsCommentOK = true;
            c.Username    = comment.Username;
            c.FullName    = comment.FullName;
            c.CommentBody = comment.Body;
            c.CommentTime = comment.Time;
            Discussion d = data.GetDiscussion(did);

            c.IsFirstComment = (d.Comments.Count == 1);
            return(this.Json(c));
        }
Beispiel #5
0
 public RechatMessage(JObject sourceJson)
 {
     SourceJson = sourceJson;
     Comment    = sourceJson.ToObject <JsonComment>();
 }
Beispiel #6
0
    // package data for upload
    public void UploadGameObjects(GameObject[] object_r, string table, bool isEditor)
    {
        string jsonobjects = "";                                                                                                                                                        // initialise new var jsontrees


        // loop through each tree and compile into json string
        // json helper and other wrapper classes not working. not sure why
        for (int i = 0; i < object_r.Length; i++)
        {
            GameObject obj        = object_r [i];
            string     jsonobject = "";



            switch (table)
            {
            case "comments":
                JsonComment jsonComment = new JsonComment();
                Comments    comment     = obj.GetComponent <Comments> ();


                print("comment = " + comment.comment);
                jsonComment.position   = obj.transform.position;
                jsonComment.scale      = obj.transform.localScale;
                jsonComment.comment    = comment.comment;
                jsonComment.timeMade   = comment.timeMade;
                jsonComment.timeUpdate = System.DateTime.Now.ToString();

                jsonobject = JsonUtility.ToJson(jsonComment);                                                                                           // encode as json

                break;

            case "cameras":
                JsonCamera jsonCamera = new JsonCamera();
                Camera     camera     = obj.GetComponent <Camera> ();
                jsonCamera.fieldOfView = camera.fieldOfView;
                jsonCamera.cameraName  = obj.name;
                jsonCamera.tag         = obj.tag;

                // check if camera is static or nested in a character
                if (obj.tag != "StaticCamera")
                {
                    // get parent transform (fps character)
                    jsonCamera.position   = obj.transform.parent.gameObject.transform.position;
                    jsonCamera.rotation   = obj.transform.parent.gameObject.transform.localEulerAngles;
                    jsonCamera.rotation.x = obj.transform.localEulerAngles.x;
                }
                else
                {
                    // get camera object transform
                    jsonCamera.position = obj.transform.position;
                    jsonCamera.rotation = obj.transform.localEulerAngles;
                }
                jsonobject = JsonUtility.ToJson(jsonCamera);                                                                                            // encode as json

                break;

            case "genObjs":
                JsonGenObj jsonGenObj = new JsonGenObj();

                // set the serilizable object with bare essentials for objects
                jsonGenObj.position = obj.transform.position;
                jsonGenObj.rotation = obj.transform.rotation.eulerAngles;
                jsonGenObj.scale    = obj.transform.localScale;
                jsonGenObj.tag      = obj.transform.tag;
                jsonGenObj.name     = obj.transform.name;

                jsonobject = JsonUtility.ToJson(jsonGenObj);                                                                                            // encode as json

                break;
            }

            jsonobjects = jsonobjects + jsonobject;                                                                                                             // build json string
            if (i < (object_r.Length - 1))                                                                                                                      // add seperating comma
            {
                jsonobjects = jsonobjects + ",";                                                                                                                // add a comma after any entry that isn't the last entry
            }
        }


        print("json an object " + wrapJson(jsonobjects));


        // create form object with data to upload.
        StartCoroutine(TransmitData(false, "objects", "json", isEditor: isEditor, isSend: true, data: wrapJson(jsonobjects), table: table));
    }