Exemplo n.º 1
0
        // GET: /Report/DocView/n
        public IActionResult DocView(int?id)
        {
            string method = "Report/DocView";

            if (NullId(id, "PendingId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                PendingReport report = null;
                if ((report = Read(id.Value, method)) == null)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                string filename = report.eFileName;
                if (IsNull(filename, "eFileName", method))
                {
                    return(RedirectToAction("Error", "Home"));
                }

                _filesys.ChangeDirectory(Config.Get("UploadDirectory"));
                byte[] file = _filesys.FileDownload(filename);

                return(new FileContentResult(file, MIME.GetMimeType(Path.GetExtension(filename))));
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 2
0
        // GET: /Circulation/Edit/n
        public IActionResult Edit(int?id)
        {
            string method = "Circulation/Edit";

            Log.Me.Debug(method + " - User: "******", CirculationId: " + (id ?? 0).ToString());
            ApplicationVersion();

            if (NullId(id, "CirculationId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                Circulation circ = null;
                if ((circ = Read(id.Value, method)) == null)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                PendingReport report   = _context.PendingReportRepo.Read(circ.PendingId);
                string        oversize = (report.eFilePath ?? "") == "OVERSIZE" ? "Yes" : "No";

                ViewData["InternalEmailDomain"] = EmailConfig.Me.InternalEmailDomain;

                return(View(new CirculationViewModel(circ, oversize)));
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 3
0
        // GET: /Circulation/Create/pendingId
        public IActionResult Create(int?id)
        {
            string method = "Circulation/Create";

            Log.Me.Debug(method + " - User: "******", PendingId: " + (id ?? 0).ToString());
            ApplicationVersion();

            if (NullId(id, "PendingId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            Circulation circ = new Circulation();

            circ.Id          = 0;
            circ.RecipientID = 0;
            circ.PendingId   = id.Value;
            circ.Name        = "";
            circ.Email       = "";
            circ.Address     = "";

            ViewData["InternalEmailDomain"] = EmailConfig.Me.InternalEmailDomain;

            PendingReport report   = _context.PendingReportRepo.Read(circ.PendingId);
            string        oversize = (report.eFilePath ?? "") == "OVERSIZE" ? "Yes" : "No";

            return(View("Edit", new CirculationViewModel(circ, oversize)));
        }
Exemplo n.º 4
0
        private bool SaveChanges(PendingReport update, string method)
        {
            if (IsNull(update, "PendingReport(update)", method))
            {
                return(false);
            }
            if (ZeroId(update.Id, "PendingId", method))
            {
                return(false);
            }

            try
            {
                PendingReport report = _context.PendingReportRepo.Read(update.Id);
                if (IsNull(report, "PendingReport(read))", method))
                {
                    return(false);
                }

                if (report.State > 0)
                {
                    return(true);                  // If we're committed, then not saving changes is the OK path
                }
                if (report.RecipientID <= 0)
                {
                    Log.Me.Warn("Report had zero RecipientId in ReportController.SaveChanges(). Report: " + update.Id.ToString());
                }
                string userid = CheckIdentity().UserId;
                if (!userid.HasValue() || userid.ToInteger() <= 0)
                {
                    Log.Me.Warn("Null or Zero userid from Session in ReportController.SaveChanges(). Report: " + update.Id.ToString());
                }
                else
                {
                    report.RecipientID = userid.ToInteger();
                }

                report.Abstract      = update.Abstract;
                report.Author        = update.Author;
                report.Axess         = update.Axess;
                report.JobNo         = update.JobNo;
                report.ReportType    = update.ReportType;
                report.SecurityLevel = update.SecurityLevel;
                report.Software      = update.Software;
                report.Title         = update.Title;

                _context.PendingReportRepo.Update(report);

                Log.Me.Info(CheckIdentity().UserName + " updated report " + update.Id.ToString());

                return(true);
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 5
0
        public PendingReport Read(int id, string method)
        {
            PendingReport report = _context.PendingReportRepo.Read(id);

            if (report == null)
            {
                Log.Me.Fatal("PendingReport with id " + id.ToString() + " could not be read in " + method);
            }
            return(report);
        }
        public void Dequeue_Always_ReturnsFirstElement()
        {
            var firstItem = new PendingReport(null, null);
            _subject.Enqueue(firstItem);
            _subject.Enqueue(new PendingReport(null, null));
            _subject.Enqueue(new PendingReport(null, null));

            var item = _subject.Dequeue();

            Assert.AreSame(firstItem, item);
        }
Exemplo n.º 7
0
        [RequestSizeLimit(52428800)]        // Handle requests up to 50 MB
        public async Task <IActionResult> UploadDocument(string pendingId)
        {
            // Generate Filename
            string filename = _context.PendingReportRepo.GenerateFilename(pendingId.ToInteger());

            Log.Me.Debug("DocumentController.UploadDocument: Filename is " + filename);

            string uploadDir = Config.Get("UploadDirectory");

            _fsys.ChangeDirectory(uploadDir);

            try
            {
                int reason = await Uploader.Upload(Request, _fsys, uploadDir, filename, _sizeLimit, _extensions);

                if (reason > 0)
                {
                    string message = null;
                    if (reason == 415)
                    {
                        message = "Type of file not accepted";
                    }
                    if (reason == 413)
                    {
                        message = "File too large";
                    }
                    Log.Me.Warn(message);
                    return(StatusCode(reason, message));
                }
                else
                {
                    // Save filename
                    PendingReport report = _context.PendingReportRepo.Read(pendingId.ToInteger());
                    report.eFileName = filename;
                    string check = _context.PendingReportRepo.CheckFileSize(_fsys, report, Config.Get("UploadDirectory"));
                    if (check != null)
                    {
                        report.eFilePath = "OVERSIZE";
                    }
                    _context.PendingReportRepo.Update(report);
                    Log.Me.Info(CheckIdentity().UserName + " uploaded file " + filename + " to report " + pendingId);
                }
            }
            catch (Exception ex)
            {
                Log.Me.Error(ex.Message);
                ModelState.AddModelError("File", ex.Message);
                BadRequest(ModelState);
            }

            return(Created(nameof(DocumentController), null));
        }
Exemplo n.º 8
0
        public ActionResult CirculationEdit(PendingReport update)
        {
            string method = "Report/CirculationEdit";

            if (SaveChanges(update, method))
            {
                return(RedirectToAction("Index", "Circulation", new { id = update.Id }));
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 9
0
        public ActionResult Edit(PendingReport update)
        {
            string method = "Report/Edit[Post]";

            if (SaveChanges(update, method))
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 10
0
        public ActionResult DocUpload(PendingReport update)
        {
            string method = "Report/DocUpload";

            if (SaveChanges(update, method))
            {
                return(RedirectToAction("Index", "Document", new { id = update.Id }));
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 11
0
        // GET: /Circulation/Add?pendingId=x&recipientId=y
        public IActionResult Add(int?recipientId, int?pendingId)
        {
            string method = "Circulation/Add";

            if (NullId(recipientId, "RecipientId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }
            if (NullId(pendingId, "PendingId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            Recipient r = _context.RecipientRepo.Read(recipientId);

            if (r == null)
            {
                Log.Me.Fatal("Recipient with id " + recipientId.ToString() + " could not be read in Circulation/Add");
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                Circulation circ = new Circulation();
                circ.Id          = 0;
                circ.RecipientID = recipientId;
                circ.PendingId   = pendingId ?? 0;
                circ.Name        = r.Name;
                circ.Email       = r.Email;
                circ.Address     = r.Address;
                //int? circId = _context.CirculationRepo.Create(circ);

                //Log.Me.Info(CheckIdentity().UserName + " added circulation to report " + circ.PendingId.ToString());

                //return RedirectToAction("Edit", "Circulation", new { id = circId });

                PendingReport report   = _context.PendingReportRepo.Read(circ.PendingId);
                string        oversize = (report.eFilePath ?? "") == "OVERSIZE" ? "Yes" : "No";

                ViewData["InternalEmailDomain"] = EmailConfig.Me.InternalEmailDomain;

                return(View("Edit", new CirculationViewModel(circ, oversize)));
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 12
0
        public ActionResult Create(CreateReportPostModel vm)
        {
            string method = "Report/Create[Post]";

            string userid = CheckIdentity().UserId;

            if (!userid.HasValue() || userid.ToInteger() <= 0)
            {
                Log.Me.Warn("Null or Zero userid in ReportController.Create() for Report " + vm.ReportNo);
            }

            try
            {
                PendingReport report = new PendingReport();
                report.ReportNo    = vm.ReportNo;
                report.ReportYear  = "20" + vm.Year;
                report.ReportType  = vm.ReportType;
                report.RecipientID = userid.ToInteger();

                //if (!ModelState.IsValid) return View(report);

                int pendingId = 0;
                if (vm.CheckNDT)
                {
                    pendingId = _context.PendingReportRepo.Create(report);
                }
                else
                {
                    pendingId = _context.PendingReportRepo.CreateNonNDT(report);
                }

                if (ZeroId(pendingId, "PendingId", method))
                {
                    return(RedirectToAction("Error", "Home"));
                }

                Log.Me.Info(CheckIdentity().UserName + " created report " + pendingId.ToString());

                return(RedirectToAction("Edit", "Report", new { id = pendingId }));
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 13
0
        // GET: /Report/Edit/n
        public IActionResult Edit(int?id, string commiterror = null)
        {
            string method = "Report/Edit";

            Log.Me.Debug(method + " - User: "******", PendingId: " + (id ?? 0).ToString());
            ApplicationVersion();

            if (NullId(id, "PendingId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                PendingReport pr = null;
                if ((pr = Read(id.Value, method)) == null)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                StandingData sd = _context.StandingDataRepo.Load();

                ViewData["RecipientMessage"] = "- " + _context.CirculationRepo.RecipientMessage(id.Value);
                if (commiterror != null)
                {
                    ViewData["CommitError"] = commiterror;
                }
                ViewData["UploadMax"] = ((int)((Config.Get("FileSizeLimit").ToLong()) / (1024 * 1024))).ToString() + "Mb";

                PendingReportViewModel report = new PendingReportViewModel(pr, sd);

                //Log.Me.Info("ReportType='" + report.ReportType + "'");
                //foreach (SelectListItem item in report.ReportTypes) Log.Me.Info("ReportTypeSelect: '" + item.Text + "' = '" + item.Value + "'");

                return(View(report));
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + ": " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 14
0
        // GET: /Circulation/Index/n
        public IActionResult Index(int?id)
        {
            string method = "Circulation/Index";

            Log.Me.Debug(method + " - User: "******", PendingId: " + (id ?? 0).ToString());
            ApplicationVersion();

            if (NullId(id, "PendingId", "Circulation/Index"))
            {
                return(RedirectToAction("Error", "Home"));
            }

            ViewData["pendingId"] = (id.Value.ToString());

            PendingReport report = _context.PendingReportRepo.Read(id.Value);

            ViewData["Editable"] = report.State > 1 ? "No" : "Yes";

            return(View());
        }
Exemplo n.º 15
0
        public IActionResult Index(int?id)
        {
            string method = "Document/Index";

            Log.Me.Debug(method + " - User: "******", PendingId: " + (id ?? 0).ToString());
            ApplicationVersion();

            if (NullId(id, "PendingId", method))
            {
                return(RedirectToAction("Error", "Home"));
            }
            PendingReport report = _context.PendingReportRepo.Read(id);

            if (IsNull(report, "PendingReport", method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            ViewData["PendingId"] = report.PendingId.ToString();

            return(View());
        }
Exemplo n.º 16
0
 static bool CheckPendingReport(PendingReport p, PendingReport testdata)
 {
     return(
         p.ReportNo == testdata.ReportNo &&
         p.ReportType.Trim() == testdata.ReportType.Trim() &&
         p.ReportYear.Trim() == testdata.ReportYear.Trim() &&
         p.Title == testdata.Title &&
         p.Author == testdata.Author &&
         p.Abstract == testdata.Abstract &&
         p.JobNo == testdata.JobNo &&
         p.Software == testdata.Software &&
         p.CreationDate == testdata.CreationDate &&
         p.Axess == testdata.Axess &&
         p.SecurityLevel == testdata.SecurityLevel &&
         p.State == testdata.State &&
         p.Deleted == testdata.Deleted &&
         p.RecipientID == testdata.RecipientID &&
         p.eFilePath == testdata.eFilePath &&
         p.eFileName == testdata.eFileName &&
         p.CID == testdata.CID &&
         p.DateSent == testdata.DateSent
         );
 }
Exemplo n.º 17
0
        public PendingReportViewModel(PendingReport pr, StandingData sd)
        {
            if (pr != null && sd != null)
            {
                this.Abstract      = pr.Abstract;
                this.Author        = pr.Author;
                this.Axess         = pr.Axess;
                this.CID           = pr.CID;
                this.CreationDate  = pr.CreationDate;
                this.DateSent      = pr.DateSent;
                this.Deleted       = pr.Deleted;
                this.eFileName     = pr.eFileName;
                this.eFilePath     = pr.eFilePath;
                this.JobNo         = pr.JobNo;
                this.RecipientID   = pr.RecipientID;
                this.ReportNo      = pr.ReportNo;
                this.ReportType    = pr.ReportType;
                this.ReportYear    = pr.ReportYear;
                this.SecurityLevel = pr.SecurityLevel;
                this.Software      = pr.Software;
                this.State         = pr.State;
                this.Title         = pr.Title;

                this.ReportTypes = new List <SelectListItem>();
                foreach (ReportType type in sd.ReportTypes)
                {
                    this.ReportTypes.Add(new SelectListItem(type.Code, type.Code));
                }

                this.SecurityLevels = new List <SelectListItem>();
                foreach (SecurityLevel level in sd.SecurityLevels)
                {
                    this.SecurityLevels.Add(new SelectListItem(level.Text, level.Code.ToString()));
                }
            }
        }
Exemplo n.º 18
0
        public ActionResult Commit(PendingReport update)
        {
            if (update.State > 0)
            {
                Log.Me.Error("There shouldn't even be a Commit button on the form!");
                return(RedirectToAction("Error", "Home"));
            }

            string method = "Report/Commit[Post]";

            if (!SaveChanges(update, method))
            {
                return(RedirectToAction("Error", "Home"));
            }

            try
            {
                string commiterror = _context.PendingReportRepo.CommitReport(_filesys, update.Id);

                if (commiterror == null)
                {
                    Log.Me.Info(CheckIdentity().UserName + " committed report " + update.Id.ToString());

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Edit", "Report", new { id = update.PendingId, commiterror = commiterror }));
                }
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + " (at stage Commit): " + ex.Message);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 19
0
        [RequestSizeLimit(52428800)]        // Handle requests up to 50 MB
        public async Task <IActionResult> Upload(IList <IFormFile> files, string pendingId)
        {
            string method = "Document/Upload";

            Log.Me.Debug(method + " - User: "******", PendingId: " + (pendingId ?? "not provided"));
            ApplicationVersion();

            if (IsNull(pendingId, "PendingId", method))
            {
                return(StatusCode(400, "No pendingId"));
            }

            try
            {
                // Generate Filename
                string filename = _context.PendingReportRepo.GenerateFilename(pendingId.ToInteger());
                if (IsNull(filename, "filename", method))
                {
                    return(StatusCode(400, "No filename"));
                }
                Log.Me.Debug(method + ": Filename is " + filename);

                if (files.Count == 0)
                {
                    Log.Me.Error(method + " no document uploaded for pendingId: " + pendingId);
                    return(StatusCode(400, "No document"));
                }

                IFormFile source   = files.FirstOrDefault();
                int       progress = await UploadFile(source, _fsys, filename, _sizeLimit);

                if (progress == 4)
                {
                    // Save filename
                    PendingReport report = _context.PendingReportRepo.Read(pendingId.ToInteger());
                    report.eFileName = filename;
                    string check = _context.PendingReportRepo.CheckFileSize(_fsys, report, Config.Get("UploadDirectory"));
                    if (check != null)
                    {
                        report.eFilePath = "OVERSIZE";
                    }
                    _context.PendingReportRepo.Update(report);
                    Log.Me.Info(CheckIdentity().UserName + " uploaded file " + filename + " to report " + pendingId.ToString());
                }
                else
                {
                    string message = null;
                    int    code    = 0;
                    if (progress == 0)
                    {
                        message = "File empty or too large:   " + filename; code = 413;
                    }
                    else if (progress == 1)
                    {
                        message = "Failed to upload file:     " + filename; code = 400;
                    }
                    else if (progress == 2)
                    {
                        message = "Type of file not accepted: " + filename; code = 415;
                    }
                    else if (progress == 3)
                    {
                        message = "Failed to save file:       " + filename; code = 500;
                    }
                    Log.Me.Warn(message);
                    return(StatusCode(code, message));
                }
            }
            catch (Exception ex)
            {
                Log.Me.Error("Exception in " + method + " :" + ex.Message);
                return(StatusCode(500, "Internal Error. See logs."));
            }

            return(this.Content("success"));
        }