예제 #1
0
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var settings           = ApplicationUtils.GetSettings(siteId);
                var dataInfo           = new DataInfo();
                var departmentInfoList = DepartmentManager.GetDepartmentInfoList(siteId);

                return(Ok(new
                {
                    Value = dataInfo,
                    DepartmentInfoList = departmentInfoList,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var settings    = ApplicationUtils.GetSettings(siteId);
                var categories  = CategoryManager.GetCategoryInfoList(siteId);
                var departments = DepartmentManager.GetDepartmentInfoList(siteId);

                return(Ok(new
                {
                    Categories = categories,
                    Departments = departments,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var settings = ApplicationUtils.GetSettings(siteId);

                var type = request.GetPostString("type");
                if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsClosed)))
                {
                    settings.IsClosed = request.GetPostBool(nameof(Settings.IsClosed).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }
                else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.DaysWarning)))
                {
                    settings.DaysWarning = request.GetPostInt(nameof(Settings.DaysWarning).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }
                else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.DaysDeadline)))
                {
                    settings.DaysDeadline = request.GetPostInt(nameof(Settings.DaysDeadline).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }
                else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsDeleteAllowed)))
                {
                    settings.IsDeleteAllowed = request.GetPostBool(nameof(Settings.IsDeleteAllowed).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }
                else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsSelectCategory)))
                {
                    settings.IsSelectCategory = request.GetPostBool(nameof(Settings.IsSelectCategory).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }
                else if (ApplicationUtils.EqualsIgnoreCase(type, nameof(Settings.IsSelectDepartment)))
                {
                    settings.IsSelectDepartment = request.GetPostBool(nameof(Settings.IsSelectDepartment).ToCamelCase());
                    Context.ConfigApi.SetConfig(ApplicationUtils.PluginId, siteId, settings);
                }

                return(Ok(new { }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");

                var settings           = ApplicationUtils.GetSettings(siteId);
                var dataInfo           = new DataInfo();
                var departmentInfoList = DepartmentManager.GetDepartmentInfoList(siteId);

                return(Ok(new
                {
                    Value = dataInfo,
                    DepartmentInfoList = departmentInfoList,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var settings = ApplicationUtils.GetSettings(siteId);

                return(Ok(new
                {
                    Value = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var dataId = request.GetQueryInt("dataId");

                var dataInfo = Main.DataRepository.GetDataInfo(dataId);

                IList <FileInfo> fileInfoList = new List <FileInfo>();
                if (dataInfo.IsReplyFiles)
                {
                    fileInfoList = Main.FileRepository.GetFileInfoList(siteId, dataId);
                }

                var logInfoList = Main.LogRepository.GetLogInfoList(siteId, dataId);
                var settings    = ApplicationUtils.GetSettings(siteId);

                return(Ok(new
                {
                    Value = dataInfo,
                    LogInfoList = logInfoList,
                    FileInfoList = fileInfoList,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult List()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, ApplicationUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var pageType  = request.GetQueryString("pageType");
                var stateList = new List <DataState>();
                if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeAccept))
                {
                    stateList.Add(DataState.New);
                }
                else if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeReply))
                {
                    stateList.Add(DataState.Accepted);
                    stateList.Add(DataState.Redo);
                }
                else if (StringUtils.EqualsIgnoreCase(pageType, ApplicationUtils.PageTypeCheck))
                {
                    stateList.Add(DataState.Replied);
                }
                else
                {
                    var state = request.GetQueryString("state");
                    if (!string.IsNullOrEmpty(state))
                    {
                        stateList.Add(DataState.ToDataState(state));
                    }
                }

                var page         = request.GetQueryInt("page", 1);
                var isSearch     = request.GetQueryBool("isSearch");
                var keyword      = request.GetQueryString("keyword");
                var departmentId = request.GetQueryInt("departmentId");

                int totalCount;
                var isSiteAdmin          = request.AdminPermissions.IsSiteAdmin(siteId);
                var userDepartmentIdList = new List <int>();

                if (isSiteAdmin)
                {
                    if (isSearch)
                    {
                        totalCount = Main.DataRepository.GetCount(siteId, stateList, keyword, departmentId);
                    }
                    else
                    {
                        keyword      = string.Empty;
                        departmentId = 0;
                        totalCount   = DataCountManager.GetCount(siteId, stateList);
                    }
                }
                else
                {
                    userDepartmentIdList = DepartmentManager.GetDepartmentIdList(siteId, request.AdminName);
                    totalCount           = Main.DataRepository.GetUserCount(siteId, stateList, keyword, departmentId, userDepartmentIdList);
                }

                var pages = Convert.ToInt32(Math.Ceiling((double)totalCount / ApplicationUtils.PageSize));
                if (pages == 0)
                {
                    pages = 1;
                }
                if (page > pages)
                {
                    page = pages;
                }

                IList <DataInfo> dataInfoList;
                if (totalCount == 0)
                {
                    dataInfoList = new List <DataInfo>();
                }
                else
                {
                    if (isSiteAdmin)
                    {
                        if (totalCount <= ApplicationUtils.PageSize)
                        {
                            dataInfoList = Main.DataRepository.GetDataInfoList(siteId, stateList, keyword, departmentId, 0, totalCount);
                        }
                        else
                        {
                            if (page == 0)
                            {
                                page = 1;
                            }
                            var offset = (page - 1) * ApplicationUtils.PageSize;
                            var limit  = totalCount - offset > ApplicationUtils.PageSize
                                ? ApplicationUtils.PageSize
                                : totalCount - offset;
                            dataInfoList = Main.DataRepository.GetDataInfoList(siteId, stateList, keyword, departmentId, offset, limit);
                        }
                    }
                    else
                    {
                        if (page == 0)
                        {
                            page = 1;
                        }
                        var offset = (page - 1) * ApplicationUtils.PageSize;
                        var limit  = totalCount - offset > ApplicationUtils.PageSize
                            ? ApplicationUtils.PageSize
                            : totalCount - offset;
                        dataInfoList = Main.DataRepository.GetUserDataInfoList(siteId, stateList, keyword, departmentId, userDepartmentIdList, offset, limit);
                    }
                }

                List <DepartmentInfo>    departmentInfoList = null;
                Dictionary <string, int> countDict          = null;
                Settings settings = null;

                if (page == 1)
                {
                    if (isSiteAdmin)
                    {
                        departmentInfoList = DepartmentManager.GetDepartmentInfoList(siteId);
                    }
                    else
                    {
                        departmentInfoList = new List <DepartmentInfo>();
                        foreach (var userDepartmentId in userDepartmentIdList)
                        {
                            departmentInfoList.Add(DepartmentManager.GetDepartmentInfo(siteId, userDepartmentId));
                        }
                    }

                    countDict = new Dictionary <string, int>
                    {
                        { "All", DataCountManager.GetTotalCount(siteId) }
                    };
                    foreach (var state in DataState.AllStates)
                    {
                        countDict.Add(state.Value, DataCountManager.GetCount(siteId, state));
                    }

                    settings = ApplicationUtils.GetSettings(siteId);
                }

                return(Ok(new
                {
                    Value = dataInfoList,
                    Count = totalCount,
                    Pages = pages,
                    Page = page,
                    DepartmentInfoList = departmentInfoList,
                    CountDict = countDict,
                    Settings = settings
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }