private bool ValidateValue(DucValueDto ducValue, DucTypes ducType) { return(ducValue.ValueInt.HasValue || ducValue.ValueDate.HasValue || ducValue.ValueText.TrimHasValue() || ducValue.ValueHtml.TrimHasValue() || ducValue.ValueUrl.TrimHasValue()); }
private void CollectValues(DucValueDto ducValue, NameValueCollection formData, DucTypes ducType, ReferenceInfoDto reference) { switch (ducType) { case DucTypes.SubTitle: case DucTypes.Text: case DucTypes.TextArea: ducValue.ValueText = formData[DucHelper.GetClientId(ducValue.DucId)]; break; case DucTypes.Html: case DucTypes.HtmlArea: ducValue.ValueHtml = formData[DucHelper.GetClientId(ducValue.DucId)]; break; case DucTypes.Image: string fileId = string.Format(UIConst.FileKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); string colTitle = string.Format(UIConst.ImageTitleKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); string title = formData[colTitle]; // Deal with image upload HttpPostedFileBase file = Request.Files[fileId]; if (null != file && file.ContentLength > 0) { // Save file and get result FileSaveResult fileResult = FileHelper.SaveFile(title, file); if (fileResult.IsSuccessful) { ducValue.ValueUrl = fileResult.FileUri; ducValue.ValueText = fileResult.Title; // Save image as Document DocumentDto document = new DocumentDto(); document.Title = fileResult.Title; document.ContentUri = fileResult.FileUri; document.OriginFile = file.FileName; document.OriginSource = "Reference"; document.IssuedDate = DateTime.Now; IDocumentService service = ServiceLocator.Current.GetInstance <IDocumentService>(); IFacadeUpdateResult <DocumentData> result = service.SaveDocument(document); } else { } } else { string col1Name = string.Format(UIConst.ValueUrlKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); string col2Name = string.Format(UIConst.ValueTextKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); ducValue.ValueUrl = formData[col1Name]; ducValue.ValueText = formData[col2Name]; } break; case DucTypes.Integer: int valueInteger; if (int.TryParse(formData[DucHelper.GetClientId(ducValue.DucId)], out valueInteger)) { ducValue.ValueInt = valueInteger; } break; case DucTypes.Hyperlink: string col3Name = string.Format(UIConst.ValueUrlKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); string col4Name = string.Format(UIConst.ValueTextKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); ducValue.ValueUrl = formData[col3Name]; ducValue.ValueText = formData[col4Name]; break; case DucTypes.Datetime: break; case DucTypes.ReferenceList: string col21Name = string.Format(UIConst.ValueIntKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); string col22Name = string.Format(UIConst.ValueTextKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); int valueInt; if (int.TryParse(formData[col21Name], out valueInt)) { ducValue.ValueInt = valueInt; } ducValue.ValueText = formData[col22Name]; break; case DucTypes.ReferenceCollection: string col5Name = string.Format(UIConst.ValueIntKeyFormatString, DucHelper.GetClientId(ducValue.DucId)); int value5Int; if (int.TryParse(formData[col5Name], out value5Int)) { ducValue.ValueInt = value5Int; } break; default: break; } }