public void ToSelectListItemsTests() { //Arrange DocumentTypeModels models = new DocumentTypeModels(); DocumentTypeModel model = new DocumentTypeModel { Id = 1, Description = "Item1", Extension = "ext1" }; models.DocumentTypes.Add(model); model = new DocumentTypeModel { Id = 2, Description = "Item2", Extension = "ext2" }; models.DocumentTypes.Add(model); //Act var result = models.ToSelectListItems(); //Assert Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); Assert.IsTrue(result.Exists(i => i.Value == "1" && i.Text == "Item1 (ext1)")); Assert.IsTrue(result.Exists(i => i.Value == "2" && i.Text == "Item2 (ext2)")); }
public void GetDocumentTypesTest() { var docType = new DocumentTypeModels(); var docTypes = docType.GetDocumentTypes(InvoiceSubtypes.ValidationRuleSet.Government); Assert.IsNotNull(docTypes); }
public void GetREfDocTypesTest() { var docType = new DocumentTypeModels(); var docTypes = docType.GetReferenceDocumentTypes(InvoiceSubtypes.ValidationRuleSet.Government); Assert.IsNotNull(docTypes); var sel = docTypes.Where(x => x.CodeEnglish.StartsWith("Cancel")); Assert.AreEqual(0, sel.Count()); }
public void ToSelectListItemsInvalidTests() { //Arrange DocumentTypeModels models = new DocumentTypeModels { DocumentTypes = null }; //Act var result = models.ToSelectListItems(); //Assert Assert.IsNull(result); }
/// <summary> /// Converts an instance of <see cref="DocumentTypeModels"/> into a list of <see cref="SelectListItem"/> /// </summary> /// <param name="documentTypes"></param> /// <returns></returns> public static List <SelectListItem> ToSelectListItems(this DocumentTypeModels documentTypes) { if (documentTypes?.DocumentTypes == null || !documentTypes.DocumentTypes.Any()) { return(null); } return(documentTypes.DocumentTypes.Select(documentType => new SelectListItem { Value = documentType.Id.ToString(), Text = $"{documentType.Description} ({documentType.Extension})" }) .ToList()); }
/// <summary> /// Retrieves a list of document types /// </summary> /// <param name="email"></param> /// <param name="rooturl"></param> /// <param name="encodedId"></param> /// <returns></returns> public async Task <DocumentTypeModels> GetDocumentTypes(string email, string rooturl, string encodedId) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId)) { return(null); } string queryname = WebTasksTypeConstants.GetDocumentTypes; string queryterms = WebApiServices.GetEmailJsonQuerySearchTerms(email); string url = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}"; DocumentTypeModels result = null; LoggingService service = new LoggingService(); var stopwatch = new Stopwatch(); try { var response = await new WebApiServices().GetData(url, encodedId); if (!string.IsNullOrEmpty(response)) { result = new SerializerServices() .DeserializeObject <DocumentTypeModels>(response.NormalizeJsonString()); } } catch (Exception ex) { service.TrackException(ex); throw; } finally { stopwatch.Stop(); var properties = new Dictionary <string, string> { { "UserEmail", email }, { "WebServicesEndpoint", rooturl }, { "EncodedId", encodedId } }; service.TrackEvent(LoggingServiceConstants.GetDocumentTypes, stopwatch.Elapsed, properties); } return(result); }
/// <summary> /// Return the Document Type for the specified Document Type ID /// </summary> /// <param name="documentTypeId"></param> /// <param name="documentTypes"></param> /// <returns></returns> public DocumentTypeModel GetDocumentTypeForDocument(int documentTypeId, DocumentTypeModels documentTypes) { DocumentTypeModel result = null; if (documentTypes?.DocumentTypes == null || !documentTypes.DocumentTypes.Any() || documentTypeId <= 0) { return(null); } result = new DocumentTypeModel(); foreach (var documentType in documentTypes.DocumentTypes) { if (documentType.Id != documentTypeId) { continue; } result = documentType; break; } return(result); }
/// <summary> /// Determines of the file extension is supported /// </summary> /// <param name="fileExtension"></param> /// <param name="documentTypes"></param> /// <returns></returns> public bool IsFileTypeSupported(string fileExtension, DocumentTypeModels documentTypes) { if (string.IsNullOrEmpty(fileExtension) || documentTypes?.DocumentTypes == null || !documentTypes.DocumentTypes.Any()) { return(false); } bool result = false; foreach (var documentType in documentTypes.DocumentTypes) { if (string.Compare(fileExtension, documentType.Extension, StringComparison.OrdinalIgnoreCase) != 0) { continue; } result = true; break; } return(result); }
public RelatedDocumentViewModel(IUnityContainer uc, IDialogService dlg, DocumentTypeModels documentTypes) : base(uc, dlg) { // _refInvDate = DateTime.Today; _refComment = ""; _refTypeList.DropDownList.Add(new DropDownListViewModel() { Code = RefType.Keine.ToString(), DisplayText = "Kein Verweis" }); _refTypeList.DropDownList.Add(new DropDownListViewModel() { Code = RefType.Storno.ToString(), DisplayText = "Storno" }); _refTypeList.DropDownList.Add(new DropDownListViewModel() { Code = RefType.Verweis.ToString(), DisplayText = "Verweis" }); _refSelectedDocType = "Invoice"; _documentTypes = documentTypes; _refDocTypes.GetList(_documentTypes.GetReferenceDocumentTypes(CurrentSelectedValidation)); }
private bool ValidateUpload(IEnumerable <IFormFile> files) { //ensure all information is correctly filled in before proceeding bool isValid = true; if (files == null || !files.Any()) { this.ErrorMessage = StringConstants.DocumentNoFileSelectedError; isValid = false; } if (isValid && files.Count() != 1) { this.ErrorMessage = StringConstants.DocumentFileSelectedError; isValid = false; } string description = Request.Form["document_details_description_upload"]; if (isValid && string.IsNullOrEmpty(description)) { this.ErrorMessage = StringConstants.DocumentNoDescription; isValid = false; } string type = Request.Form["document_details_type_upload"]; if (isValid && string.IsNullOrEmpty(type)) { this.ErrorMessage = StringConstants.DocumentNoTypeSelected; isValid = false; } string category = Request.Form["document_details_category_upload"]; if (isValid && string.IsNullOrEmpty(category)) { this.ErrorMessage = StringConstants.DocumentNoCategorySelected; isValid = false; } string fileExtension = ""; DocumentTypeModels documentTypes = null; if (isValid) { var selectedfile = files.First(); FileInfo fi = new FileInfo(selectedfile.FileName); //remove the period from the file extension fileExtension = fi.Extension.Substring(1); documentTypes = HttpContext.Session.Get <DocumentTypeModels>(SessionConstants.DocumentTypes); } //determine if the selected document for upload has a supported file extension if (isValid) { bool validFileType = new DocumentManagerPageModelService().IsFileTypeSupported(fileExtension, documentTypes); if (!validFileType) { this.ErrorMessage = StringConstants.DocumentUnsupportedFileType; isValid = false; } } //determine if the selected document type matches the document's file extension if (isValid) { var documentType = new DocumentManagerPageModelService().GetDocumentTypeForDocument(Convert.ToInt32(type), documentTypes); if (string.Compare(fileExtension, documentType.Extension, StringComparison.OrdinalIgnoreCase) != 0) { this.ErrorMessage = StringConstants.DocumentMismatchedFileType; isValid = false; } } return(isValid); }