Beispiel #1
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request  = Context.GetCurrentRequest();
                var formInfo = FormManager.GetFormInfoByPost(request);
                if (formInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

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

                var logInfo = logId > 0
                    ? LogDao.GetLogInfo(logId)
                    : new LogInfo
                {
                    FormId  = formInfo.Id,
                    AddDate = DateTime.Now
                };
                var fieldInfoList = FieldManager.GetFieldInfoList(formInfo.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 = FormUtils.ToDateTime(request.GetPostString(fieldInfo.Title));
                            logInfo.Set(fieldInfo.Title, dt.ToLocalTime());
                        }

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

                if (logId == 0)
                {
                    LogDao.Insert(formInfo, logInfo);
                }
                else
                {
                    LogDao.Update(logInfo);
                }

                return(Ok(new{}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }