Beispiel #1
0
        public ActionResult Create(ThreadDTO thread)
        {
            try
            {
                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

                if (authCookie != null)
                {
                    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    JavaScriptSerializer      serializer = new JavaScriptSerializer();

                    TableUserDTO serializeModel = serializer.Deserialize <TableUserDTO>(authTicket.UserData);

                    if (serializeModel != null)
                    {
                        if (ModelState.IsValid)
                        {
                            thread.User = serializeModel;
                            db.ForumThreadSet.Add(Mapper.MapTo(thread));
                            db.SaveChanges();

                            return(RedirectToAction("Index", "Home"));
                        }

                        return(View(thread));
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            throw new UnauthorizedAccessException("You must be logged to create threads");
        }
Beispiel #2
0
        public ActionResult Create(CommentDTO comment)
        {
            if (comment.ThreadId < 1)
            {
                throw new UnauthorizedAccessException("The threadId is invalid");
            }

            try
            {
                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

                if (authCookie != null)
                {
                    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    JavaScriptSerializer      serializer = new JavaScriptSerializer();

                    TableUserDTO serializeModel = serializer.Deserialize <TableUserDTO>(authTicket.UserData);

                    if (serializeModel != null)
                    {
                        if (ModelState.IsValid)
                        {
                            comment.User = serializeModel;

                            db.CommentSet.Add(Mapper.MapTo(comment));
                            db.SaveChanges();

                            return(RedirectToAction("Details", "Thread", new { id = comment.ThreadId }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            throw new UnauthorizedAccessException("You must be logged to create threads");
        }
Beispiel #3
0
        // GET: CommentDTO/Create/{threadId}
        public ActionResult Create(int?threadId)
        {
            if (!threadId.HasValue || threadId < 1)
            {
                throw new UnauthorizedAccessException("The threadId is invalid");
            }

            try
            {
                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

                if (authCookie != null)
                {
                    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    JavaScriptSerializer      serializer = new JavaScriptSerializer();

                    TableUserDTO serializeModel = serializer.Deserialize <TableUserDTO>(authTicket.UserData);
                    CommentDTO   comment        = new CommentDTO();

                    if (serializeModel != null)
                    {
                        if (ModelState.IsValid)
                        {
                            comment.User     = serializeModel;
                            comment.ThreadId = threadId.Value;

                            return(View(comment));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            throw new UnauthorizedAccessException("You must be logged to create threads");
        }