コード例 #1
0
        public ActionResult Comment(string documentId)
        {
            if (documentId != null)
            {
                int documentIdToFind = 0;
                try
                {
                    documentIdToFind = Convert.ToInt32(new Encryption().DecryptString(documentId, User.Identity.Name));
                }
                catch (FormatException fe)
                {
                    TempData["error_message"] = "Document does not exist";

                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                        Exception  = fe.Message,
                        Time       = DateTime.Now,
                        Message    = "User tried to manually search for a document in the address bar"
                    }
                        );
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    TempData["error_message"] = "Document unavailable";
                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = "Comment",
                        Exception  = ex.Message,
                        Time       = DateTime.Now,
                        Message    = "documentId decryption error"
                    }
                        );
                    return(RedirectToAction("Index"));
                }

                DocumentsOperations dops = new DocumentsOperations();
                if (dops.DoesDocumentExist(documentIdToFind))
                {
                    try
                    {
                        Document d = dops.GetDocument(documentIdToFind);
                        if (dops.IsReviewerAllocatedToDocument(User.Identity.Name, documentIdToFind) || d.Username_fk == User.Identity.Name)
                        {
                            ViewData["document_title"] = d.Title;
                            ViewData["document_id"]    = new Encryption().EncryptString(d.Id.ToString(), User.Identity.Name);

                            return(View());
                        }
                        else
                        {
                            TempData["error_message"] = "You are not a reviewer of this document";
                            new LogsOperations().AddLog(
                                new Log()
                            {
                                Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                Exception  = "User is not document's reviewer",
                                Time       = DateTime.Now,
                                Message    = "User is not document's reviewer"
                            }
                                );
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (DocumentExistsException ex)
                    {
                        TempData["error_message"] = ex.Message;
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = ex.Message,
                            Time       = DateTime.Now,
                            Message    = ex.Message
                        }
                            );

                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        TempData["error_message"] = ex.Message;
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = ex.Message,
                            Time       = DateTime.Now,
                            Message    = "Error checking reviewing permissions"
                        }
                            );

                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    TempData["error_message"] = "Document does not exist";
                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                        Exception  = "Document does not exist",
                        Time       = DateTime.Now,
                        Message    = "Document does not exist"
                    }
                        );
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                TempData["error_message"] = "No document selected";
                new LogsOperations().AddLog(
                    new Log()
                {
                    Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                    Exception  = "No document selected",
                    Time       = DateTime.Now,
                    Message    = "No document selected"
                }
                    );
                return(RedirectToAction("Index"));
            }
        }
コード例 #2
0
        public ActionResult Comment(string document, Comment c)
        {
            if (document != null)
            {
                if (c.Comment1 != null)
                {
                    int documentIdToFind = 0;
                    try
                    {
                        documentIdToFind = Convert.ToInt32(new Encryption().DecryptString(document, User.Identity.Name));
                    }
                    catch (FormatException fe)
                    {
                        TempData["error_message"] = "Document does not exist";

                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = fe.Message,
                            Time       = DateTime.Now,
                            Message    = "User tried to manually search for a document in the address bar"
                        }
                            );
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        TempData["error_message"] = "Document unavailable";
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = "Comment",
                            Exception  = ex.Message,
                            Time       = DateTime.Now,
                            Message    = "documentId decryption error"
                        }
                            );
                        return(RedirectToAction("Index"));
                    }

                    DocumentsOperations dops = new DocumentsOperations();
                    if (dops.DoesDocumentExist(documentIdToFind))
                    {
                        try
                        {
                            Document d = dops.GetDocument(documentIdToFind);
                            if (dops.IsReviewerAllocatedToDocument(User.Identity.Name, documentIdToFind))
                            {
                                ViewData["document_id"] = new Encryption().EncryptString(d.Id.ToString(), User.Identity.Name);
                                try
                                {
                                    dops.AddComment(d, c, User.Identity.Name);
                                    ModelState.Clear();
                                }
                                catch (Exception ex)
                                {
                                    ViewData["error_message"] = ex.Message;
                                    new LogsOperations().AddLog(
                                        new Log()
                                    {
                                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                        Exception  = ex.Message,
                                        Time       = DateTime.Now,
                                        Message    = "Adding comment exception"
                                    }
                                        );

                                    return(RedirectToAction("Review"));
                                }

                                return(View());
                            }
                            else
                            {
                                TempData["error_message"] = "You are not a reviewer of this document";
                                new LogsOperations().AddLog(
                                    new Log()
                                {
                                    Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                    Exception  = "User is not document's reviewer",
                                    Time       = DateTime.Now,
                                    Message    = "User is not document's reviewer"
                                }
                                    );
                                return(RedirectToAction("Review"));
                            }
                        }
                        catch (DocumentExistsException ex)
                        {
                            TempData["error_message"] = ex.Message;
                            new LogsOperations().AddLog(
                                new Log()
                            {
                                Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                Exception  = ex.Message,
                                Time       = DateTime.Now,
                                Message    = ex.Message
                            }
                                );

                            return(RedirectToAction("Review"));
                        }
                        catch (Exception ex)
                        {
                            TempData["error_message"] = ex.Message;
                            new LogsOperations().AddLog(
                                new Log()
                            {
                                Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                Exception  = ex.Message,
                                Time       = DateTime.Now,
                                Message    = "Error checking reviewing permissions"
                            }
                                );

                            return(RedirectToAction("Review"));
                        }
                    }
                    else
                    {
                        TempData["error_message"] = "Document does not exist";
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = "Document does not exist",
                            Time       = DateTime.Now,
                            Message    = "Document does not exist"
                        }
                            );
                        return(RedirectToAction("Review"));
                    }
                }
                else
                {
                    TempData["error_message"] = "Comment cannot be empty";
                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                        Exception  = "No comment entered",
                        Time       = DateTime.Now,
                        Message    = "No comment entered"
                    }
                        );
                    return(RedirectToAction("Review"));
                }
            }
            else
            {
                TempData["error_message"] = "No document selected";
                new LogsOperations().AddLog(
                    new Log()
                {
                    Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                    Exception  = "No document selected",
                    Time       = DateTime.Now,
                    Message    = "No document selected"
                }
                    );
                return(RedirectToAction("Review"));
            }

            //DocumentsOperations dops = new DocumentsOperations();
            //Document d = dops.GetDocument(document);
            //ViewData["document_id"] = d.Id;
            //try
            //{
            //    dops.AddComment(d, c, User.Identity.Name);
            //    ModelState.Clear();
            //}
            //catch (Exception ex)
            //{
            //    ViewData["error_message"] = ex.Message;
            //    new LogsOperations().AddLog(
            //        new Log()
            //        {
            //            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
            //            Exception = ex.Message,
            //            Time = DateTime.Now,
            //            Message = "Adding comment exception"
            //        }
            //    );
            //}
            //return View();
        }
コード例 #3
0
        public ActionResult DownloadFile(string documentId)
        {
            if (documentId != null)
            {
                int decryptedDocumentId = 0;
                try
                {
                    decryptedDocumentId = Convert.ToInt32(new Encryption().DecryptString(documentId, User.Identity.Name));
                }
                catch (FormatException fe)
                {
                    TempData["error_message"] = "Document does not exist";

                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                        Exception  = fe.Message,
                        Time       = DateTime.Now,
                        Message    = "User tried to manually search for a document in the address bar"
                    }
                        );
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    TempData["error_message"] = "Document unavailable";
                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = "Comment",
                        Exception  = ex.Message,
                        Time       = DateTime.Now,
                        Message    = "documentId decryption error"
                    }
                        );
                    return(RedirectToAction("Index"));
                }


                DocumentsOperations dops = new DocumentsOperations();
                if (dops.DoesDocumentExist(decryptedDocumentId))
                {
                    try
                    {
                        Document d = dops.GetDocument(decryptedDocumentId);
                        if (dops.IsReviewerAllocatedToDocument(User.Identity.Name, decryptedDocumentId))
                        {
                            string absolutePath = Server.MapPath(d.FilePath);

                            if (System.IO.File.Exists(absolutePath) == true)
                            {
                                FileStream   fs = System.IO.File.OpenRead(absolutePath);
                                MemoryStream ms = new MemoryStream();
                                fs.CopyTo(ms);
                                ms.Position = 0;

                                try
                                {
                                    if (new Encryption().DigitalVerify(ms, new UsersOperations().GetUser(d.Username_fk).PublicKey, new DocumentsOperations().GetDocument(decryptedDocumentId).Signature))
                                    {
                                        MemoryStream msOut = new MemoryStream(new Encryption().HybridDecryptFile(ms, new UsersOperations().GetUser(d.Username_fk).PrivateKey));
                                        msOut.Position = 0;
                                        return(File(msOut.ToArray(), System.Net.Mime.MediaTypeNames.Application.Octet, d.FilePath));
                                    }
                                    else
                                    {
                                        TempData["error_message"] = "Unable to verify document";
                                        new LogsOperations().AddLog(
                                            new Log()
                                        {
                                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                            Exception  = "Unable to verify document",
                                            Time       = DateTime.Now,
                                            Message    = "Unable to verify document"
                                        }
                                            );
                                        return(RedirectToAction("Index"));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    TempData["error_message"] = "Unable to verify document";
                                    new LogsOperations().AddLog(
                                        new Log()
                                    {
                                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                        Exception  = "Unable to verify document",
                                        Time       = DateTime.Now,
                                        Message    = "Unable to verify document"
                                    }
                                        );
                                    return(RedirectToAction("Index"));
                                }
                            }
                            else
                            {
                                TempData["error_message"] = "Document does not exist";
                                new LogsOperations().AddLog(
                                    new Log()
                                {
                                    Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                    Exception  = "Document does not exist",
                                    Time       = DateTime.Now,
                                    Message    = "Document does not exist"
                                }
                                    );
                                return(RedirectToAction("Index"));
                            }
                        }
                        else
                        {
                            TempData["error_message"] = "You are not a reviewer of this document";
                            new LogsOperations().AddLog(
                                new Log()
                            {
                                Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                                Exception  = "User is not document's reviewer",
                                Time       = DateTime.Now,
                                Message    = "User is not document's reviewer"
                            }
                                );
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (DocumentExistsException ex)
                    {
                        TempData["error_message"] = ex.Message;
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = ex.Message,
                            Time       = DateTime.Now,
                            Message    = ex.Message
                        }
                            );

                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        TempData["error_message"] = "Unable to download document";
                        new LogsOperations().AddLog(
                            new Log()
                        {
                            Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                            Exception  = ex.Message,
                            Time       = DateTime.Now,
                            Message    = "Unable to download document"
                        }
                            );
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    new LogsOperations().AddLog(
                        new Log()
                    {
                        Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                        Exception  = "Document does not exist",
                        Time       = DateTime.Now,
                        Message    = "Document does not exist"
                    }
                        );
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                TempData["error_message"] = "No document selected";
                new LogsOperations().AddLog(
                    new Log()
                {
                    Controller = RouteData.Values["controller"].ToString() + "/" + RouteData.Values["action"].ToString(),
                    Exception  = "No document selected",
                    Time       = DateTime.Now,
                    Message    = "No document selected"
                }
                    );

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