Exemple #1
0
        public JsonResult EditUploadJS(int uploadId)
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = "There was a problem loading the upload."
            };
            ExtractViewModel model = new ExtractViewModel();

            try
            {
                var extract = ExtractViewModel.GetExtract(_unitOfWork, uploadId);

                if (extract == null)
                {
                    return(Json(ajaxResponse));
                }

                model.ExtractId = uploadId;
                model.Name      = extract.Name;
                model.NameSave  = extract.Name;

                ajaxResponse.Success = true;
                ajaxResponse.TheData = model;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
            }

            return(Json(ajaxResponse));
        }
Exemple #2
0
        public JsonResult GetUploadNameJS(int uploadId)
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = "An error occurred while getting the upload name."
            };

            try
            {
                string uploadName;

                var upload = ExtractViewModel.GetExtract(_unitOfWork, uploadId);

                if (upload != null)
                {
                    uploadName = upload.Name;
                }
                else
                {
                    uploadName = "unknown";
                }

                ajaxResponse.Success = true;
                ajaxResponse.TheData = uploadName;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
            }

            return(Json(ajaxResponse));
        }
Exemple #3
0
        public JsonResult LoadUploadsJS(DTParameters param)
        {
            try
            {
                var dtSource = ExtractViewModel.GetExtracts(_unitOfWork);

                List <ExtractViewModel> data = new ResultSet_Extracts().GetResult(param.Search.Value, param.SortOrder, param.Start, param.Length, dtSource, null);
                int count = new ResultSet_Extracts().Count(param.Search.Value, dtSource, null);

                DTResult <ExtractViewModel> result = new DTResult <ExtractViewModel>
                {
                    draw            = param.Draw,
                    data            = data,
                    recordsFiltered = count,
                    recordsTotal    = count
                };

                return(Json(result));
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                return(Json(new { error = ex.Message }));
            }
        }
Exemple #4
0
        public JsonResult LoadUploadItemsJS(DTParameters param)    //, int extractId)    //, int auditId)
        {
            try
            {
                var dtSource = ExtractViewModel.GetExtractItems(_unitOfWork, param.PrimaryId);

                //var dtsource = _unitOfWork.AuditExtracts.GetAll()
                //.Select(s => new ManageStatusesViewModel { StatusId = s.StatusId, Name = s.Name, Description = s.Description, IncludeInAuditYN = s.IncludeInAuditYN }).ToList();
                List <ExtractItemModel> data = new ResultSet_ExtractItems().GetResult(param.Search.Value, param.SortOrder, param.Start, param.Length, dtSource, null);
                int count = new ResultSet_ExtractItems().Count(param.Search.Value, dtSource, null);

                DTResult <ExtractItemModel> result = new DTResult <ExtractItemModel>
                {
                    draw            = param.Draw,
                    data            = data,
                    recordsFiltered = count,
                    recordsTotal    = count
                };

                return(Json(result));
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                return(Json(new { error = ex.Message }));
            }
        }
Exemple #5
0
        public JsonResult SaveUploadJS(ExtractViewModel extract)
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = "An error occurred while saving the upload."
            };

            //should have already been caught by client, but check again
            if (!ModelState.IsValid)
            {
                ajaxResponse.Message = "Please complete all required form fields.";
                return(Json(ajaxResponse));
            }

            try
            {
                extract.TheUnitOfWork = _unitOfWork;

                if (!extract.IsUniqueYN())   //Uniqueness of extract
                {
                    ajaxResponse.Message = "The upload name already exists.";
                    return(Json(ajaxResponse));
                }

                int id = extract.UpdateAndSave();

                ajaxResponse.Message = "Success";
                ajaxResponse.Success = true;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
            }

            return(Json(ajaxResponse));
        }
        /// <summary>
        /// Builds delimited string of Master facilities for use in comparison.
        /// </summary>
        /// <param name="facilities">The facilities in raw format.</param>
        /// <param name="auditName">Name of the audit.</param>
        /// <returns>Delimited string of master facilities to use in comparison</returns>
        static private string CalculateDatabaseFacilitiesForComparison(string facilities, string auditName)
        {
            if (string.IsNullOrWhiteSpace(facilities))
            {
                return(string.Empty);
            }

            List <string> exceptions = new List <string>();
            string        facResult  = Utility.StringToSortedIntString(facilities, ",", ref exceptions).Trim();

            if (exceptions.Count > 0)
            {
                string msg = string.Format("One or more non-numeric DB Facility was found during audit {0}: {1}", auditName, facilities);
                ErrorTools.HandleError(new ApplicationException(msg), ErrorLevel.NonFatal);
            }
            return(facResult);
        }
        /// <summary>
        /// Builds delimited string of Optimum facilities for use in comparison.
        /// </summary>
        /// <param name="facilities">The Optimum facilities embedded with other text.</param>
        /// <param name="auditName">Name of the Audit.</param>
        /// <returns>Delimited string of facilities to use in comparison</returns>
        static private string CalculateOptimumFacilitiesForComparison(string facilities, string auditName)
        {
            if (string.IsNullOrWhiteSpace(facilities))
            {
                return(string.Empty);
            }

            string        optimumFacilitiesDelim = Properties.Settings.Default.OptimumFacilitiesDelim[1].ToString();
            List <string> exceptions             = new List <string>();
            string        facResult = Utility.StringToSortedIntString(facilities, optimumFacilitiesDelim, ref exceptions).Trim();

            if (exceptions.Count > 0)
            {
                string msg = string.Format("One or more non-numeric Optimum Facility was found during audit {0}: {1}", auditName, facilities);
                ErrorTools.HandleError(new ApplicationException(msg), ErrorLevel.NonFatal);
            }

            return(facResult);
        }
        /// <summary>
        /// Builds delimited string of Optimum templates for use in comparison.
        /// </summary>
        /// <param name="templates">The Optimum templates embedded in other text.</param>
        /// <param name="auditName">Name of the Audit.</param>
        /// <returns>Delimited string of Optimum templates for comparison</returns>
        static public string CalculateOptimumTemplatesForComparison(string templates, string auditName)
        {
            string templatesUse = (templates ?? string.Empty).Trim().ToLower();

            if (string.IsNullOrWhiteSpace(templatesUse))
            {
                return(string.Empty);
            }

            //pull out numerics as strings
            string[] arrTemplates = Regex.Split(templatesUse, @"\D+").Where(i => i.Length > 0).ToArray();

            //convert to actual numeric type - by this point there should be only numeric strings
            List <int> arrTemplateVals = new List <int>();
            bool       isError         = false;

            foreach (string template in arrTemplates)
            {
                int number;
                if (int.TryParse((template ?? string.Empty).Trim(), out number))
                {
                    arrTemplateVals.Add(number);
                }
                else
                {
                    isError = true;
                }
            }

            if (isError)
            {
                //shouldn't happen but log it
                string msg = string.Format("One or more non-numeric Optimum Template was found during audit {0}: {1}", auditName, templates);
                ErrorTools.HandleError(new ApplicationException(msg), ErrorLevel.NonFatal);
            }

            var    valsSorted      = arrTemplateVals.OrderBy(o => o).ToList();
            string templatesResult = Utility.IntListToDelimited(valsSorted, ",").Trim();

            return(templatesResult);
        }
Exemple #9
0
        public JsonResult DeleteUploadJS(ExtractViewModel extract)
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = string.Format("There was a problem deleting upload, ID: {0}", extract.ExtractId)
            };

            if (extract.ExtractId == 0)     //shouldn't happen
            {
                return(Json(ajaxResponse));
            }

            try
            {
                var existingExCount = _unitOfWork.Audits.GetAll().Where(a => a.ExtractId == extract.ExtractId).Count();

                if (existingExCount > 0)    //can't delete, its is in use
                {
                    ajaxResponse.Message = "Cannot delete an upload used in an audit";
                    return(Json(ajaxResponse));
                }

                int result = ExtractViewModel.DeleteExtract(_unitOfWork, (int)extract.ExtractId);

                if (result < 1)
                {
                    return(Json(ajaxResponse));
                }

                ajaxResponse.Message = "Success";
                ajaxResponse.Success = true;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
            }

            return(Json(ajaxResponse));
        }
Exemple #10
0
        public JsonResult SaveAndUploadDataJS()
        {
            var ajaxResponse = new AjaxResponse {
                Success = false, Message = "An error occurred while saving the upload."
            };

            //added additional try/catches for debugging a problem

            try
            {
                //should have already been caught by client, but check again
                if (!ModelState.IsValid)
                {
                    ajaxResponse.Message = "Please complete all required form fields.";
                    return(Json(ajaxResponse));
                }
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                ajaxResponse.Message = "There was a problem validating your input, please try again.";
                return(Json(ajaxResponse));
            }

            //validation
            HttpPostedFileBase hpf;

            try
            {
                if (Request.Files.Count != 1)
                {
                    ajaxResponse.Message = "More than one upload file was specified.";
                    return(Json(ajaxResponse));
                }

                hpf = Request.Files[0] as HttpPostedFileBase;
                if (hpf.ContentLength == 0)
                {
                    ajaxResponse.Message = "The specified upload file is empty.";
                    return(Json(ajaxResponse));
                }

                int maxFileBytes = Properties.Settings.Default.MaxUploadSize;
                if (hpf.ContentLength > maxFileBytes)
                {
                    ajaxResponse.Message = string.Format("The upload file should not exceed {0} bytes.", maxFileBytes);
                    return(Json(ajaxResponse));
                }

                if (!Request.Files[0].FileName.ToLower().EndsWith(".csv"))
                {
                    ajaxResponse.Message = "The upload file must be a CSV file.";
                    return(Json(ajaxResponse));
                }
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                ajaxResponse.Message = "There was a problem validating the specified file.";
                return(Json(ajaxResponse));
            }

            //int extractId = Convert.ToInt32(Request.Form["extractIdJS"]);
            string           extractName;
            string           internalUserId;
            ExtractViewModel extract;

            ajaxResponse.Success = false;

            try
            {
                extractName    = Request.Form["extractNameJS"];
                internalUserId = Utility.GetAspNetUserName(this);
                extract        = ExtractViewModel.NewExtract(_unitOfWork, extractName, internalUserId);

                if (!extract.IsUniqueYN())   //Uniqueness of extract
                {
                    ajaxResponse.Message = "The upload name already exists.";
                    return(Json(ajaxResponse));
                }
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                ajaxResponse.Message = "There was a problem uniqueness of upload file.";
                return(Json(ajaxResponse));
            }

            try
            {
                extract.ExtractId = extract.AddAndSave();

                if (extract.ExtractId == 0)
                {
                    return(Json(ajaxResponse));
                }

                ajaxResponse.Id = extract.ExtractId;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                ajaxResponse.Message = "There was a problem saving the main upload record.";
                return(Json(ajaxResponse));
            }

            //proceed with upload
            try
            {
                extract.UploadExtract(hpf.InputStream);

                ajaxResponse.Message = "Success";
                ajaxResponse.Success = true;
            }
            catch (Exception ex)
            {
                ErrorTools.HandleError(ex, ErrorLevel.NonFatal);    //just log, no redirect
                ajaxResponse.Message = "An error occurred while uploading the data.";
            }

            return(Json(ajaxResponse));
        }