Ejemplo n.º 1
0
        public ActionResult EditSubmission(EditSubmission model)
        {
            var existingSubmission = _db.Submissions.Find(model.SubmissionId);

            if (existingSubmission == null)
            {
                return(Json("Unauthorized edit or submission not found.", JsonRequestBehavior.AllowGet));
            }

            if (existingSubmission.IsDeleted)
            {
                return(Json("This submission has been deleted.", JsonRequestBehavior.AllowGet));
            }
            if (existingSubmission.UserName.Trim() != User.Identity.Name)
            {
                return(Json("Unauthorized edit.", JsonRequestBehavior.AllowGet));
            }

            existingSubmission.Content      = model.SubmissionContent;
            existingSubmission.LastEditDate = DateTime.Now;

            _db.SaveChanges();
            DataCache.Submission.Remove(model.SubmissionId);

            // parse the new submission through markdown formatter and then return the formatted submission so that it can replace the existing html submission which just got modified
            var formattedSubmission = Formatting.FormatMessage(model.SubmissionContent);

            return(Json(new { response = formattedSubmission }));
        }
Ejemplo n.º 2
0
        public ActionResult EditSubmission(EditSubmission model)
        {
            var existingSubmission = db.Messages.Find(model.SubmissionId);

            if (existingSubmission != null)
            {
                if (existingSubmission.Name.Trim() == User.Identity.Name)
                {
                    existingSubmission.MessageContent = model.SubmissionContent;
                    existingSubmission.LastEditDate   = System.DateTime.Now;
                    db.SaveChanges();

                    //parse the new submission through markdown formatter and then return the formatted submission so that it can replace the existing html submission which just got modified
                    string formattedSubmission = Utils.Formatting.FormatMessage(model.SubmissionContent);
                    return(Json(new { response = formattedSubmission }));
                }
                else
                {
                    return(Json("Unauthorized edit.", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json("Unauthorized edit or submission not found.", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> EditSubmission(EditSubmission model)
        {
            var cmd = new EditSubmissionCommand(model.SubmissionId, new Domain.Models.UserSubmission()
            {
                Content = model.SubmissionContent
            });
            var response = await cmd.Execute();

            if (response.Success)
            {
                DataCache.Submission.Remove(model.SubmissionId);
                CacheHandler.Instance.Remove(CachingKey.Submission(model.SubmissionId));
                return(Json(new { response = response.Response.FormattedContent }));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, response.Message));
            }
        }
        public async Task <ActionResult> EditSubmission([FromBody] EditSubmission model)
        {
            if (ModelState.IsValid)
            {
                var cmd = new EditSubmissionCommand(model.SubmissionId, new Domain.Models.UserSubmission()
                {
                    Content = model.SubmissionContent
                }).SetUserContext(User);
                var response = await cmd.Execute();

                if (response.Success)
                {
                    DataCache.Submission.Remove(model.SubmissionId);
                    CacheHandler.Instance.Remove(CachingKey.Submission(model.SubmissionId));
                    //return Json(new { response = response.Response.FormattedContent });
                }
                return(JsonResult(response));
            }

            return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage())));
        }