예제 #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));
 }
예제 #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 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));
            }
        }
예제 #3
0
        public static NameValueCollection ImportFields(int siteId, int pollId, string styleDirectoryPath, bool isHistoric)
        {
            var titleAttributeNameDict = new NameValueCollection();

            if (!Directory.Exists(styleDirectoryPath))
            {
                return(titleAttributeNameDict);
            }

            var filePaths = Directory.GetFiles(styleDirectoryPath);

            foreach (var filePath in filePaths)
            {
                var feed = AtomFeed.Load(new FileStream(filePath, FileMode.Open));

                var title = GetDcElementContent(feed.AdditionalElements, nameof(FieldInfo.Title));
                if (isHistoric)
                {
                    var attributeName = GetDcElementContent(feed.AdditionalElements, "AttributeName");
                    title = GetDcElementContent(feed.AdditionalElements, "DisplayName");

                    titleAttributeNameDict[title] = attributeName;
                }
                var fieldType = GetDcElementContent(feed.AdditionalElements, nameof(FieldInfo.FieldType));
                if (isHistoric)
                {
                    fieldType = GetDcElementContent(feed.AdditionalElements, "InputType");
                }
                var taxis = PollUtils.ToInt(GetDcElementContent(feed.AdditionalElements, "Taxis"), 0);

                var fieldInfo = new FieldInfo
                {
                    PollId    = pollId,
                    Taxis     = taxis,
                    Title     = title,
                    FieldType = fieldType
                };

                var fieldItems = new List <FieldItemInfo>();
                foreach (AtomEntry entry in feed.Entries)
                {
                    var itemValue  = GetDcElementContent(entry.AdditionalElements, "ItemValue");
                    var isSelected = PollUtils.ToBool(GetDcElementContent(entry.AdditionalElements, "IsSelected"), false);

                    fieldItems.Add(new FieldItemInfo
                    {
                        PollId     = pollId,
                        FieldId    = 0,
                        Value      = itemValue,
                        IsSelected = isSelected
                    });
                }

                if (fieldItems.Count > 0)
                {
                    fieldInfo.Items = fieldItems;
                }

                if (FieldManager.Repository.IsTitleExists(pollId, title))
                {
                    FieldManager.Repository.Delete(pollId, title);
                }
                FieldManager.Repository.Insert(siteId, fieldInfo);
            }

            return(titleAttributeNameDict);
        }