Ejemplo n.º 1
0
        public IHttpActionResult Delete()
        {
            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 = LogDao.GetLogInfo(logId);
                if (logInfo == null)
                {
                    return(NotFound());
                }

                LogDao.Delete(formInfo, logInfo);

                var pages = Convert.ToInt32(Math.Ceiling((double)formInfo.TotalCount / FormUtils.PageSize));
                if (pages == 0)
                {
                    pages = 1;
                }
                var page = request.GetQueryInt("page", 1);
                if (page > pages)
                {
                    page = pages;
                }
                var logInfoList = LogDao.GetLogInfoList(formInfo, false, page);

                var logs = new List <Dictionary <string, object> >();
                foreach (var info in logInfoList)
                {
                    logs.Add(info.ToDictionary());
                }

                return(Ok(new
                {
                    Value = logs,
                    Count = formInfo.TotalCount,
                    Pages = pages,
                    Page = page
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }