Exemple #1
0
 private static object GetValue(ScopedElementCollection additionalElements, TableColumn tableColumn)
 {
     if (tableColumn.DataType == DataType.Boolean)
     {
         return(PollUtils.ToBool(GetDcElementContent(additionalElements, tableColumn.AttributeName), false));
     }
     if (tableColumn.DataType == DataType.DateTime)
     {
         return(PollUtils.ToDateTime(GetDcElementContent(additionalElements, tableColumn.AttributeName)));
     }
     if (tableColumn.DataType == DataType.Decimal)
     {
         return(PollUtils.ToDecimal(GetDcElementContent(additionalElements, tableColumn.AttributeName), 0));
     }
     if (tableColumn.DataType == DataType.Integer)
     {
         return(PollUtils.ToInt(GetDcElementContent(additionalElements, tableColumn.AttributeName), 0));
     }
     if (tableColumn.DataType == DataType.Text)
     {
         return(Decrypt(GetDcElementContent(additionalElements, tableColumn.AttributeName)));
     }
     return(GetDcElementContent(additionalElements, tableColumn.AttributeName));
 }
Exemple #2
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var pollInfo = PollManager.GetPollInfo(request);
                if (pollInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var logId = request.GetPostInt("logId");

                var logInfo = logId > 0
                    ? LogManager.Repository.GetLogInfo(logId)
                    : new LogInfo
                {
                    PollId  = pollInfo.Id,
                    AddDate = DateTime.Now
                };
                var fieldInfoList = FieldManager.GetFieldInfoList(pollInfo.Id);
                foreach (var fieldInfo in fieldInfoList)
                {
                    if (request.IsPostExists(fieldInfo.Title))
                    {
                        var value = request.GetPostString(fieldInfo.Title);
                        if (fieldInfo.FieldType == InputType.Date.Value || fieldInfo.FieldType == InputType.DateTime.Value)
                        {
                            var dt = PollUtils.ToDateTime(request.GetPostString(fieldInfo.Title));
                            logInfo.Set(fieldInfo.Title, dt.ToLocalTime());
                        }

                        else
                        {
                            logInfo.Set(fieldInfo.Title, value);
                        }
                    }
                }

                if (logId == 0)
                {
                    logInfo.Id = LogManager.Repository.Insert(pollInfo, logInfo);
                    NotifyManager.SendNotify(pollInfo, fieldInfoList, logInfo);
                }
                else
                {
                    LogManager.Repository.Update(logInfo);
                }

                return(Ok(new{}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #3
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var pollInfo = PollManager.GetPollInfo(request);
                if (pollInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var type = request.GetPostString("type");
                if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsClosed)))
                {
                    pollInfo.IsClosed = request.GetPostBool(nameof(PollInfo.IsClosed));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.Title)))
                {
                    pollInfo.Title = request.GetPostString(nameof(PollInfo.Title));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.Description)))
                {
                    pollInfo.Description = request.GetPostString(nameof(PollInfo.Description));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsImage)))
                {
                    pollInfo.IsImage = request.GetPostBool(nameof(PollInfo.IsImage));
                    pollInfo.IsUrl   = request.GetPostBool(nameof(PollInfo.IsUrl));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsCheckbox)))
                {
                    pollInfo.IsCheckbox  = request.GetPostBool(nameof(PollInfo.IsCheckbox));
                    pollInfo.CheckboxMin = PollUtils.ToInt(request.GetPostString(nameof(PollInfo.CheckboxMin)));
                    pollInfo.CheckboxMax = PollUtils.ToInt(request.GetPostString(nameof(PollInfo.CheckboxMax)));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsTimeout)))
                {
                    pollInfo.IsTimeout   = request.GetPostBool(nameof(PollInfo.IsTimeout));
                    pollInfo.TimeToStart = PollUtils.ToDateTime(request.GetPostString(nameof(PollInfo.TimeToStart)));
                    pollInfo.TimeToEnd   = PollUtils.ToDateTime(request.GetPostString(nameof(PollInfo.TimeToEnd)));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsCaptcha)))
                {
                    pollInfo.IsCaptcha = request.GetPostBool(nameof(PollInfo.IsCaptcha));
                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsAdministratorSmsNotify)))
                {
                    pollInfo.IsAdministratorSmsNotify     = request.GetPostBool(nameof(PollInfo.IsAdministratorSmsNotify));
                    pollInfo.AdministratorSmsNotifyTplId  = request.GetPostString(nameof(PollInfo.AdministratorSmsNotifyTplId));
                    pollInfo.AdministratorSmsNotifyKeys   = request.GetPostString(nameof(PollInfo.AdministratorSmsNotifyKeys));
                    pollInfo.AdministratorSmsNotifyMobile = request.GetPostString(nameof(PollInfo.AdministratorSmsNotifyMobile));

                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsAdministratorMailNotify)))
                {
                    pollInfo.IsAdministratorMailNotify      = request.GetPostBool(nameof(PollInfo.IsAdministratorMailNotify));
                    pollInfo.AdministratorMailNotifyAddress = request.GetPostString(nameof(PollInfo.AdministratorMailNotifyAddress));

                    PollManager.Repository.Update(pollInfo);
                }
                else if (PollUtils.EqualsIgnoreCase(type, nameof(PollInfo.IsUserSmsNotify)))
                {
                    pollInfo.IsUserSmsNotify         = request.GetPostBool(nameof(PollInfo.IsUserSmsNotify));
                    pollInfo.UserSmsNotifyTplId      = request.GetPostString(nameof(PollInfo.UserSmsNotifyTplId));
                    pollInfo.UserSmsNotifyKeys       = request.GetPostString(nameof(PollInfo.UserSmsNotifyKeys));
                    pollInfo.UserSmsNotifyMobileName = request.GetPostString(nameof(PollInfo.UserSmsNotifyMobileName));

                    PollManager.Repository.Update(pollInfo);
                }

                return(Ok(new { }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #4
0
        public static void ImportPoll(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 pollInfo = new PollInfo();

                foreach (var tableColumn in PollManager.Repository.TableColumns)
                {
                    var value = GetValue(feed.AdditionalElements, tableColumn);
                    pollInfo.Set(tableColumn.AttributeName, value);
                }

                pollInfo.SiteId = siteId;

                if (isHistoric)
                {
                    pollInfo.Title = GetDcElementContent(feed.AdditionalElements, "InputName");
                }

                var srcPollInfo = PollManager.GetPollInfo(siteId, pollInfo.Title);
                if (srcPollInfo != null)
                {
                    if (overwrite)
                    {
                        PollManager.Repository.Delete(siteId, srcPollInfo.Id);
                    }
                    else
                    {
                        pollInfo.Title = PollManager.Repository.GetImportTitle(siteId, pollInfo.Title);
                    }
                }

                pollInfo.Id = PollManager.Repository.Insert(pollInfo);

                var directoryName = GetDcElementContent(feed.AdditionalElements, "Id");
                if (isHistoric)
                {
                    directoryName = GetDcElementContent(feed.AdditionalElements, "InputID");
                }
                var titleAttributeNameDict = new NameValueCollection();
                if (!string.IsNullOrEmpty(directoryName))
                {
                    var fieldDirectoryPath = PollUtils.PathCombine(directoryPath, directoryName);
                    titleAttributeNameDict = ImportFields(siteId, pollInfo.Id, fieldDirectoryPath, isHistoric);
                }

                foreach (AtomEntry entry in feed.Entries)
                {
                    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.AddDate = PollUtils.ToDateTime(GetDcElementContent(entry.AdditionalElements, "adddate"));
                    }

                    LogManager.Repository.Insert(pollInfo, logInfo);
                }
            }
        }