Example #1
0
        public ActionResult AddPost(string description, string subject, string content)
        {
            User user = CheckAuthentication(Request.Cookies[id]);

            if (user == null)
            {
                return(RedirectToAction("Authorize"));
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(description) && !string.IsNullOrWhiteSpace(subject) && !string.IsNullOrWhiteSpace(content))
                {
                    try
                    {
                        Guid    subjKey = Guid.Parse(subject);
                        Subject subj    = subjectRepo.GetSubject(subjKey);
                        content = Uri.UnescapeDataString(content);
                        Post newPost = new Post(user.UserKey, subj.SubjectKey, description, content);

                        postRepo.AddPost(newPost);

                        return(new EmptyResult());
                    }
                    catch
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
        }