예제 #1
0
        //keep for potential of future testing of db connection

        /*
         * public FolderController(IFolderRepository repository) {
         *  this.repository = repository;
         * }
         */

        //currently the role is coming as a query value, needs to be a role check through better security
        /// <summary>
        /// Takes the ClientId and packages some data up to give to publicVMController
        /// Might just comebine this and PublicVM together, somewhat redudant to have two controllers
        /// </summary>
        /// <param name="Number">The Client Id</param>
        /// <param name="Role">Whether the person has authoratative powers in Archive View</param>
        /// <returns></returns>
        //Since all exceptions go to the same view, dont see any reason to use different handerror attributes
        // GET: Folder
        public ActionResult Index([Bind(Prefix = "ClientId")] string Number, string Role = "", string PublicName = "")
        {
            tbl_Folder folder = null;

            CustomHelpers.InMemoryCache cacheprovider = new CustomHelpers.InMemoryCache();

            folder = repository.SelectByNumber(Number);

            if (folder == null)
            {
                NoResultException exception = new NoResultException("The client may not exist or does not have any available documents.");
                exception.HelpLink          = "Please check over the provided information and try again.";
                exception.Data["Client ID"] = Number;

                throw exception;
            }
            else
            {
                //was told to eventually create a seperate role for ArchiveView
                if (HttpContext.User.IsInRole("westlandcorp\\IT-ops"))
                {
                    TempData["RoleButton"] = "Admin";

                    if (Role == "Admin")
                    {
                        TempData["Role"]       = "Admin";
                        TempData["RoleButton"] = "Client";
                    }
                    else
                    {
                        TempData["Role"] = "Client";
                    }
                }
                else
                {
                    TempData["Role"] = "Client";
                }

                //TempData["Client_Name"] = folder.Name;
                TempData["Client_Name"] = Server.UrlDecode(PublicName);

                TempData["Client_Id"] = folder.Number;
                TempData["Folder_Id"] = folder.Folder_ID; //should be a better way than carrying this variable around
            }

            cacheprovider.removeCache(folder.Folder_ID.ToString());

            return(RedirectToAction("Index", "PublicVM", new { folderId = folder.Folder_ID }));
        }
예제 #2
0
        public ActionResult Index([Bind(Prefix = "folderId")] string Folder_ID, string navBarGroup = null, string navBarItem = null, string sort = null, string searchTerm = null, string IssueYearMinRange = "-1", string IssueYearMaxRange = "", string IssueMonthMinRange = "", string IssueMonthMaxRange = "")
        {
            //**GLOBAL VARIABLES

            //TempData can be used to send data between controllers and views through one request, .keep() is used to continue keeping after one request
            //persist client name, id, search term, inputted dates
            TempData.Keep("Client_Name");
            TempData.Keep("Client_Id");
            TempData.Keep("Folder_Id");
            TempData.Keep("Role");
            TempData.Keep("RoleButton");
            //***Pseudo save state immitation
            TempData.Keep("SearchTerm");
            TempData.Keep("YearRange"); //will carry an array with allowable issue date years for custom dropdown list


            //JACKIE
            TempData["IssueYearMinRange"]  = IssueYearMinRange;
            TempData["IssueYearMaxRange"]  = IssueYearMaxRange;
            TempData["IssueMonthMinRange"] = IssueMonthMinRange;
            TempData["IssueMonthMaxRange"] = IssueMonthMaxRange;


            //ViewData["goodSearch"] = false means seachterm will return an empty result
            ViewData["goodSearch"] = true; //do i still need this var?
            //ViewData["currentNav"] used to populate view's link route value for navBarGroup, which in turn populates navBarGroup variable.  Used to save navBarGroup state
            ViewData["currentNav"] = null;

            //declare and instantiate the original full PublicVM data for the client
            IEnumerable <PublicVM> publicModel = null;

            //Admin should default see all data, while typical user should just see 1 year
            DateTime issueDateMin = ((string)TempData["Role"] == "Admin") ? today.AddYears(-30) : today.AddYears(-1);
            DateTime?issueDateMax = null;

            TempData["Version"] = System.Configuration.ConfigurationManager.AppSettings["Versioning"];



            //removing whitespaces from end of search term to use before querying
            if (searchTerm != null)
            {
                searchTerm = searchTerm.Trim();
            }

            //**POPULATING MAIN MODEL, second conditional is for no doc reference documents, a unique westland condition
            try
            {
                //right now, publicModel is full of units of DocReference x DocId
                publicModel = cacheprovider.GetOrSet(
                    Folder_ID,
                    () => publicRepository
                    .SelectAll(Folder_ID, TempData["Role"].ToString())             //find a way to cache this initial load
                    .Where(n => n.EffectiveDate != null || n.EffectiveDate == null && n.RefNumber == null || n.EffectiveDate == null && n.RefNumber != null),
                    TempData["Role"].ToString()
                    );
                //added a caching mechanism where on initial load, the model will be cached for 10 mins.
                //if no cache, it will run the default call to the db
            }
            catch
            {
                //the clientId should always exist.  if it doesnt, i would assume the user shouldnt be here, which is why i issue an exception
                NoResultException exception = new NoResultException("The client may not exist or does not have any available documents.");
                exception.HelpLink          = "Please check over the provided information and try again.";
                exception.Data["Folder ID"] = Folder_ID;

                throw exception;
            }

            //needs to be checked seperately because cant select by DocId until after deciding if we are searching by documentId or policy
            //can possibly combine into navBarGroupFilter
            if (navBarGroup != "policy")
            {
                publicModel = publicModel.GroupBy(x => x.Document_ID).Select(x => x.First());
            }


            //should only be run on initial load of page
            if (!Request.IsAjaxRequest())
            {
                //count of total records unfiltered of this client
                ViewData["allRecordsCount"] = publicModel.Count();

                //maybe should return view here already since overall count is already 0
                if (publicModel.Count() == 0)
                {
                    //maybe reword exception message
                    NoResultException exception = new NoResultException("The client does not have any available records.");
                    exception.HelpLink          = "Please check over the provided information and try again.";
                    exception.Data["Folder ID"] = Folder_ID;

                    throw exception;
                }

                //creating the options for the dropdown list
                TempData["YearRange"] = YearRangePopulate(RetrieveYear(publicModel, true), RetrieveYear(publicModel, false));

                //**Populating the navbar, put into function
                populateNavBar(publicModel);

                //pretty much should only be the initial synchronous load to come in here
                ViewData["SortOrder"] = sortAscending;
                publicModel           = publicModel
                                        .OrderByDescending(r => r.IssueDate)
                                        .ThenByDescending(r => r.ArchiveTime)
                                        .Where(r => r.IssueDate >= issueDateMin)
                                        .ToList();

                ViewData["currentRecordsCount"] = publicModel.Count();

                return(View(publicModel));
            }
            else
            {
                //If user inputs only one custom year and maybe one/two months, what should happen?
                if (String.IsNullOrEmpty(IssueYearMaxRange))
                {
                    //entered in two scenarios: 1) regular minIssueDate input and custom date where only minIssueDate is filled
                    int yearInput = (string.IsNullOrEmpty(IssueYearMinRange)) ? Int32.Parse(today.AddYears(-1).Year.ToString()) : Int32.Parse(IssueYearMinRange);

                    issueDateMin = (yearInput > 0) ? issueDateMin = new DateTime(yearInput, 1, 1) : issueDateMin = today.AddYears(yearInput);

                    yearInput = (yearInput > 0) ? yearInput - DateTime.Now.Year : yearInput;
                }
                else if (!String.IsNullOrEmpty(IssueYearMinRange) && !String.IsNullOrEmpty(IssueYearMaxRange))
                {
                    //custom dates
                    issueDateMin = FormatDate(IssueYearMinRange, IssueMonthMinRange, true);
                    issueDateMax = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false);
                }
                else
                {
                    //no input for min date under CUSTOM inputs
                    //min would be oldest issue date available
                    IssueMonthMaxRange = (String.IsNullOrEmpty(IssueMonthMaxRange)) ? "12" : IssueMonthMaxRange;
                    issueDateMin       = DateTime.ParseExact(String.Format("01/01/1985"), "d", CultureInfo.InvariantCulture);
                    issueDateMax       = FormatDate(IssueYearMaxRange, IssueMonthMaxRange, false);
                }

                //**STARTING ACTUAL FILTERING/SORTING OF MODEL**

                //*filtering by category/doctype/policy
                if (navBarGroup != null)
                {
                    publicModel = navBarGroupFilter(publicModel, navBarGroup, navBarItem);
                }

                //*filtering by date and search conditions
                if (TempData["Role"].ToString() == "Admin")
                {
                    //checks if the date filter and search term will return any results
                    //The admin search will also search for document Id within the same input (so checks tbl_Document.Description and tbl_Document.Document_Id)
                    if (!publicModel.Any(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm))))
                    {
                        //ViewData["goodSearch"] equals false means no records is found
                        ViewData["goodSearch"] = false;
                    }
                    else
                    {
                        publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) || r.Document_ID.ToString().Contains(searchTerm) == true : true)));

                        TempData["SearchTerm"] = searchTerm;
                    }
                }
                else
                {
                    //checks if the date filter and search term will return any results
                    publicModel = publicModel.Where(r => (r.IssueDate >= issueDateMin) && (issueDateMax == null || r.IssueDate <= issueDateMax) && (searchTerm == null || ((bool)ViewData["goodSearch"] ? r.Description.ToLower().Contains(searchTerm.ToLower()) == true : true)));
                }

                ViewData["currentRecordsCount"] = publicModel.Count();

                if (publicModel.Count() == 0) //not sure if needed
                {
                    ViewData["goodSearch"] = false;
                }

                TempData["SearchTerm"] = searchTerm; //not sure if needed

                //*sorting data
                publicModel = SortModel(publicModel, sort);

                //**ENDING FILTERING OF MODEL**

                if (publicModel != null)
                {
                    ViewData["SortOrder"] = sortAscending;

                    return(PartialView("_PublicTable", publicModel));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
예제 #3
0
        public ActionResult FileDisplay([Bind(Prefix = "documentId")] string id)
        {
            string MimeType = null;

            //only admins can see hidden file contents
            tbl_Document file = (User.IsInRole("IT-ops") ? documentRepository.SelectById(id, true) : documentRepository.SelectById(id, false));

            if (file == null)
            {
                NoResultException exception = new NoResultException("The document is not available or does not exist.");
                exception.HelpLink            = "Please check over the provided information and try again.";
                exception.Data["Document ID"] = id;

                throw exception;
            }
            else if (file.ArchivedFile == null)
            {
                NullReferenceException exception = new NullReferenceException("The file appears to be missing or corrupt.");
                exception.HelpLink = "Please contact ServiceNow if additional help is needed.";

                throw exception;
            }
            else if (file.ArchivedFile.Length < 100)
            {
                //rare occation of when there is a file, but possibly corrupted
                //better to use IOException, but seems like a waste to bring in a whole new package for this
                Exception exception = new Exception("The file was unable to be open.");
                exception.HelpLink            = "Please contact Support at ServiceNow";
                exception.Data["Document ID"] = id;

                throw exception;
            }
            else
            {
                //maybe can do this better than comparing strings
                switch (file.FileExtension.ToLower().Trim())
                {
                case "pdf":
                    MimeType = "application/pdf";
                    break;

                case "gif":
                    MimeType = "image/gif";
                    break;

                case "jpg":
                    MimeType = "image/jpeg";
                    break;

                case "msg":
                    MimeType = "application/vnd.outlook";
                    //HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "ppt":
                    MimeType = "application/vnd.ms-powerpoint";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "xls":
                    MimeType = "application/vnd.ms-excel";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "csv":
                    MimeType = "application/vnd.ms-excel";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "xlsx":
                    MimeType = "application/vnd.ms-excel.12";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "doc":
                case "dot":
                    MimeType = "application/msword";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                case "docx":
                    MimeType = "application/vnd.ms-word.document.12";
                    HttpContext.Response.AddHeader("Content-Disposition", "Attachment");
                    break;

                default:
                    MimeType = "text/html";
                    break;
                }
            }
            return(File(file.ArchivedFile, MimeType));
        }