public virtual JsonResult AddAttachment(int?id)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase userPostedFile = Request.Files[0];
                    {
                        var attachment = new TicketAttachment();

                        string fName = Path.GetFileName(userPostedFile.FileName);

                        attachment.FileName = fName;

                        attachment.FileSize = userPostedFile.ContentLength;
                        string mtype = userPostedFile.ContentType;
                        attachment.FileType = (string.IsNullOrEmpty(mtype) ? "application/octet-stream" : mtype);
                        byte[] fileContent = new byte[userPostedFile.ContentLength];
                        userPostedFile.InputStream.Read(fileContent, 0, userPostedFile.ContentLength);

                        var isDemo = (bool)Settings.ApplicationSettings.GetSettingValue("IsDemo");

                        if (isDemo)
                        {
                            attachment.FileContents = System.Text.Encoding.UTF8.GetBytes("The demo does not store upload content...");
                        }
                        else
                        {
                            attachment.FileContents = fileContent;
                        }
                        try
                        {
                            System.Threading.Thread.Sleep(2000);
                            int fileId = Tickets.AddPendingAttachment(id, attachment);
                            return(new JsonResult()
                            {
                                ContentType = "text/plain", Data = new { success = true, id = fileId.ToString() }
                            });
                        }
                        catch
                        {
                            return(new JsonResult());
                        }
                    }
                }
                throw new InvalidOperationException("No file data was uploaded");
            }
            throw new InvalidOperationException("The user is not authenticated.");
        }