Ejemplo n.º 1
0
        public static object Submit(IRequest request, string id)
        {
            var formId = Convert.ToInt32(id);

            var formInfo = Main.Instance.FormDao.GetFormInfo(formId);

            if (formInfo == null)
            {
                return(null);
            }

            var settings = new FormSettings(formInfo.Settings);

            var code   = request.GetPostString("code");
            var cookie = request.GetCookie("ss-form:" + id);

            if (string.IsNullOrEmpty(cookie) || !Utils.EqualsIgnoreCase(cookie, code))
            {
                throw new Exception("提交失败,验证码不正确!");
            }

            var logInfo = new LogInfo
            {
                FormId  = formId,
                AddDate = DateTime.Now
            };

            var attributes = request.GetPostObject <Dictionary <string, object> >("attributes");

            var fieldInfoList = Main.Instance.FieldDao.GetFieldInfoList(formInfo.Id, true);

            foreach (var fieldInfo in fieldInfoList)
            {
                object value;
                attributes.TryGetValue(FieldManager.GetAttributeId(fieldInfo.Id), out value);
                if (value != null && value.ToString() != "[]")
                {
                    logInfo.Set(fieldInfo.Title, value.ToString());
                    if (FieldManager.IsExtra(fieldInfo))
                    {
                        foreach (var item in fieldInfo.Items)
                        {
                            var    extrasId = FieldManager.GetExtrasId(fieldInfo.Id, item.Id);
                            object extras;
                            attributes.TryGetValue(extrasId, out extras);
                            if (!string.IsNullOrEmpty(extras?.ToString()))
                            {
                                logInfo.Set(extrasId, extras.ToString());
                            }
                        }
                    }
                }
            }

            logInfo.Id = Main.Instance.LogDao.Insert(logInfo);

            if (settings.IsAdministratorSmsNotify && !string.IsNullOrEmpty(settings.AdministratorSmsNotifyTplId) && !string.IsNullOrEmpty(settings.AdministratorSmsNotifyKeys) && !string.IsNullOrEmpty(settings.AdministratorSmsNotifyMobile))
            {
                var smsPlugin = Main.Instance.PluginApi.GetPlugin <SmsPlugin>(SmsPlugin.PluginId);
                if (smsPlugin != null && smsPlugin.IsReady)
                {
                    string errorMessage;
                    var    parameters = new Dictionary <string, string>();
                    var    keys       = settings.AdministratorSmsNotifyKeys.Split(',');
                    foreach (var key in keys)
                    {
                        if (key == nameof(LogInfo.Id))
                        {
                            parameters.Add(key, logInfo.Id.ToString());
                        }
                        else if (key == nameof(LogInfo.AddDate))
                        {
                            parameters.Add(key, logInfo.AddDate.ToString("yyyy-MM-dd HH:mm"));
                        }
                        else
                        {
                            parameters.Add(key, logInfo.GetString(key));
                        }
                    }
                    smsPlugin.Send(settings.AdministratorSmsNotifyMobile, settings.AdministratorSmsNotifyTplId, parameters, out errorMessage);
                }
            }

            return(new
            {
            });
        }