public static string GetValue(FieldInfo fieldInfo, LogInfo logInfo) { var value = string.Empty; if (logInfo.ContainsKey(fieldInfo.Title)) { if (fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value) { value = string.Join(",", PollUtils.JsonDeserialize <List <string> >(logInfo.Get <string>(fieldInfo.Title))); } else if (fieldInfo.FieldType == InputType.Date.Value) { var date = logInfo.Get <DateTime?>(fieldInfo.Title); if (date.HasValue) { value = date.Value.ToString("yyyy-MM-dd"); } } else if (fieldInfo.FieldType == InputType.DateTime.Value) { var datetime = logInfo.Get <DateTime?>(fieldInfo.Title); if (datetime.HasValue) { value = datetime.Value.ToString("yyyy-MM-dd HH:mm"); } } else { value = logInfo.Get <string>(fieldInfo.Title); } } return(value); }
public static string GetValue(FieldInfo fieldInfo, LogInfo logInfo) { var value = string.Empty; if (logInfo.ContainsKey(fieldInfo.Title)) { var fieldValue = logInfo.Get <string>(fieldInfo.Title); if (fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value) { var list = FormUtils.JsonDeserialize <List <string> >(fieldValue); if (list != null) { value = string.Join(",", list); } } else if (fieldInfo.FieldType == InputType.Date.Value) { if (!string.IsNullOrEmpty(fieldValue)) { var date = FormUtils.ToDateTime(fieldValue, DateTime.MinValue); if (date != DateTime.MinValue) { value = date.ToString("yyyy-MM-dd"); } } } else if (fieldInfo.FieldType == InputType.DateTime.Value) { if (!string.IsNullOrEmpty(fieldValue)) { var date = FormUtils.ToDateTime(fieldValue, DateTime.MinValue); if (date != DateTime.MinValue) { value = date.ToString("yyyy-MM-dd HH:mm"); } } } else { value = fieldValue; } } return(value); }
public static void ImportForm(int siteId, string directoryPath, bool overwrite) { if (!Directory.Exists(directoryPath)) { return; } var isHistoric = IsHistoric(directoryPath); var filePaths = Directory.GetFiles(directoryPath); foreach (var filePath in filePaths) { var feed = AtomFeed.Load(new FileStream(filePath, FileMode.Open)); var formInfo = new FormInfo(); foreach (var tableColumn in FormManager.Repository.TableColumns) { var value = GetValue(feed.AdditionalElements, tableColumn); formInfo.Set(tableColumn.AttributeName, value); } formInfo.SiteId = siteId; formInfo.AddDate = DateTime.Now; if (isHistoric) { formInfo.Title = GetDcElementContent(feed.AdditionalElements, "InputName"); } var srcFormInfo = FormManager.GetFormInfoByTitle(siteId, formInfo.Title); if (srcFormInfo != null) { if (overwrite) { FormManager.Repository.Delete(siteId, srcFormInfo.Id); } else { formInfo.Title = FormManager.Repository.GetImportTitle(siteId, formInfo.Title); } } formInfo.Id = FormManager.Repository.Insert(formInfo); var directoryName = GetDcElementContent(feed.AdditionalElements, "Id"); if (isHistoric) { directoryName = GetDcElementContent(feed.AdditionalElements, "InputID"); } var titleAttributeNameDict = new NameValueCollection(); if (!string.IsNullOrEmpty(directoryName)) { var fieldDirectoryPath = FormUtils.PathCombine(directoryPath, directoryName); titleAttributeNameDict = ImportFields(siteId, formInfo.Id, fieldDirectoryPath, isHistoric); } var entryList = new List <AtomEntry>(); foreach (AtomEntry entry in feed.Entries) { entryList.Add(entry); } entryList.Reverse(); foreach (var entry in entryList) { var logInfo = new LogInfo(); foreach (var tableColumn in LogManager.Repository.TableColumns) { var value = GetValue(entry.AdditionalElements, tableColumn); logInfo.Set(tableColumn.AttributeName, value); } var attributes = GetDcElementNameValueCollection(entry.AdditionalElements); foreach (string entryName in attributes.Keys) { logInfo.Set(entryName, attributes[entryName]); } if (isHistoric) { foreach (var title in titleAttributeNameDict.AllKeys) { logInfo.Set(title, logInfo.Get(titleAttributeNameDict[title])); } logInfo.ReplyContent = GetDcElementContent(entry.AdditionalElements, "Reply"); if (!string.IsNullOrEmpty(logInfo.ReplyContent)) { logInfo.IsReplied = true; } logInfo.AddDate = FormUtils.ToDateTime(GetDcElementContent(entry.AdditionalElements, "adddate")); } LogManager.Repository.Insert(formInfo, logInfo); } } }
public IHttpActionResult Get() { try { var request = Context.AuthenticatedRequest; var formInfo = FormManager.GetFormInfoByGet(request); if (formInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.MenuFormsPermission)) { return(Unauthorized()); } var logId = request.GetQueryInt("logId"); var fieldInfoList = FieldManager.GetFieldInfoList(formInfo.Id); LogInfo logInfo = null; if (logId > 0) { logInfo = LogManager.Repository.GetLogInfo(logId); } var list = new List <FieldInfo>(); foreach (var fieldInfo in fieldInfoList) { object value; if (fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value) { value = logInfo != null ? FormUtils.JsonDeserialize <List <string> >(logInfo.Get <string>(fieldInfo.Title)) : new List <string>(); } //else if (fieldInfo.FieldType == InputType.Image.Value) //{ // value = logInfo != null // ? new List<string> {logInfo.Get<string>(fieldInfo.Title)} // : new List<string>(); //} else if (fieldInfo.FieldType == InputType.Date.Value || fieldInfo.FieldType == InputType.DateTime.Value) { value = logInfo?.Get <DateTime>(fieldInfo.Title); } else { value = logInfo?.Get <string>(fieldInfo.Title); } if (value == null) { value = string.Empty; } list.Add(new FieldInfo { Id = fieldInfo.Id, Title = fieldInfo.Title, Description = fieldInfo.Description, PlaceHolder = fieldInfo.PlaceHolder, FieldType = fieldInfo.FieldType, Validate = fieldInfo.Validate, Columns = fieldInfo.Columns, Height = fieldInfo.Height, Items = fieldInfo.Items, Value = value }); } var adminToken = Context.AdminApi.GetAccessToken(request.AdminId, request.AdminName, TimeSpan.FromDays(1)); return(Ok(new { Value = list, AdminToken = adminToken })); } catch (Exception ex) { return(InternalServerError(ex)); } }