Exemple #1
0
        public async Task <IActionResult> UserProblemResultsLightAsync(string courseName, string courseYear, string problem, string user)
        {
            var results = await _dbService.Resolve().Match(
                async mongoDb => mongoDb._data
                .Find(i => i.CourseName == courseName &&
                      i.CourseYear == courseYear &&
                      i.Problem == problem &&
                      (i.User == user || i.GroupUsers.Contains(user))
                      )
                .SortByDescending(i => i.Id)
                .Limit(25)
                .Project(ProjectionDefinitions.CcData2CcDataLight)
                .ToEnumerable()
                .ToList(),
                async inMemoryDb => (await _dbService.Data.FindAsync(i => i.CourseName == courseName &&
                                                                     i.CourseYear == courseYear &&
                                                                     i.Problem == problem &&
                                                                     (i.User == user || i.GroupUsers.Contains(user))))
                .OrderByDescending(i => i.Id)
                .Take(25)
                .Select(ProjectionDefinitions.SingleCcData2CcDataLight)
                .ToList()
                );

            var response = new ApiListResponse <CcDataLight>(results);

            return(Ok(response));
        }
        public IActionResult CourseList()
        {
            var courses = _courseService
                          .GetAllowedCoursesForUser(_userService.CurrentUser)
                          .ToList();

            var singleCourses = courses
                                .SelectMany(i => i.CourseYears
                                            .Select(j => new SingleCourse
            {
                CourseRef      = i,
                Course         = i.Name,
                Year           = j.Year,
                CourseConfig   = i.CourseConfig,
                Problems       = j.Problems,
                SettingsConfig = j.SettingsConfig,
            }))
                                .OrderByDescending(i => i.Year)
                                .ThenBy(i => i.Course);

            var response = new ApiListResponse <SingleCourse>
            {
                Data   = singleCourses,
                Errors = courses
                         .Where(i => i.Errors.Any())
                         .Select(i => new ApiError
                {
                    Name   = i.Name,
                    Errors = i.Errors
                })
            };

            return(Ok(response));
        }
Exemple #3
0
        public async Task <IActionResult> NotificationsGet(string objectId, string path)
        {
            var user    = _userService.CurrentUser;
            var minDate = DateTime.Now.Subtract(TimeSpan.FromDays(30));
            var minId   = new ObjectId(minDate, 0, 0, 0);

            var notifications = await _dbService.Resolve().Match(
                async mongoDb => await mongoDb._events
                .Find(i => i.Id > minId && i.Reciever == user.Id)
                .SortByDescending(i => i.IsNew)
                .SortByDescending(i => i.Id)
                .Limit(30)
                .ToListAsync(),
                async inMemoryDb => (await _dbService.Events
                                     .FindAsync(i => i.Id > minId && i.Reciever == user.Id))
                .OrderByDescending(i => i.IsNew)
                .ThenByDescending(i => i.Id)
                .Take(30)
                .ToList()
                );

            var result = new ApiListResponse <CcEvent>(notifications);

            return(Ok(result));
        }
Exemple #4
0
        /// <summary>
        /// Sends GET request for supported Api list. Request can
        /// be cancelled providing CancellationToken.
        /// </summary>
        /// <param name="version">API method version</param>
        /// <param name="cToken">Cancellation token</param>
        /// <returns>ApiListResponse object</returns>
        public async Task <ApiListResponse> GetApiListAsync(string version = "v1", CToken cToken = default)
        {
            UrlBuilder.Host = HOST;
            UrlBuilder.AppendPath(ISTEAM_WEB_API, "GetSupportedAPIList", version);

            string          url       = UrlBuilder.PopEncodedUrl(false);
            ApiListResponse result    = null;
            Exception       exception = null;

            try
            {
                var response = await GetModelAsync <ApiListResponseParent>(url, cToken)
                               .ConfigureAwait(false);

                result = new ApiListResponse()
                {
                    Contents = response.Apilist.Interfaces
                };
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(WrapResponse(result, url, exception));
        }
Exemple #5
0
        public async Task <ApiListResponse <UserShortDataModel> > AdminGetCollection(int skip, int limit, string q)
        {
            if (skip < 0)
            {
                skip = 0;
            }
            if (limit > MAX_LIMIT)
            {
                limit = MAX_LIMIT;
            }
            else if (limit < 0)
            {
                limit = 1;
            }

            var list = await _appUserRepository.Get(skip, limit, q);

            var result = new ApiListResponse <UserShortDataModel>
            {
                Skip  = skip,
                Limit = limit,
                Total = await _appUserRepository.Count(),
                Data  = list?.Select(x => _mapper.Map <UserShortDataModel>(x)).ToList() ?? new List <UserShortDataModel>()
            };

            return(result);
        }
Exemple #6
0
        public async Task <IActionResult> UserProblemResults(string courseName, string courseYear, string problem, string user)
        {
            var results = await _dbService.Resolve().Match(
                async mongoDb => mongoDb._data
                .Find(i => i.CourseName == courseName &&
                      i.CourseYear == courseYear &&
                      i.Problem == problem &&
                      (i.User == user || i.GroupUsers.Contains(user))
                      //  && i.Action == "solve"
                      )
                .SortByDescending(i => i.Id)
                .Limit(25)
                .ToEnumerable()
                .Select(_utilService.ConvertToExtended)
                .ToList(),
                async inMemoryDb => (await _dbService.Data.FindAsync(i => i.CourseName == courseName &&
                                                                     i.CourseYear == courseYear &&
                                                                     i.Problem == problem &&
                                                                     (i.User == user || i.GroupUsers.Contains(user))))
                .OrderByDescending(i => i.Id)
                .Take(25)
                .Select(_utilService.ConvertToExtended)
                .ToList()
                );

            // var rng = new Random();
            // var options = (ProcessStatusCodes[]) Enum.GetValues(typeof(ProcessStatusCodes));
            // results.ForEach(i => i.Result.Status = (int) options[rng.Next(0, options.Length-1)]);

            var response = new ApiListResponse <CcData>(results);

            return(Ok(response));
        }
        public ApiListResponse <MeetingRoomModel> GetMeetingRoomList()
        {
            ApiListResponse <MeetingRoomModel> response = new ApiListResponse <MeetingRoomModel>()
            {
                Result = this.MeetingService.GetMeetingRoomList()
            };

            return(response);
        }
        public ApiListResponse <ExpenseAuditSummaryModel> ExpenseSummary()
        {
            ApiListResponse <ExpenseAuditSummaryModel> response = new ApiListResponse <ExpenseAuditSummaryModel>()
            {
                Result = this.ExpenseService.ExpenseSummary(this.Member.Id)
            };

            return(response);
        }
Exemple #9
0
        public ApiListResponse <ApproveOrderModel> SearchOrdersByEnglishName(string englishname)
        {
            ApiListResponse <ApproveOrderModel> response = new ApiListResponse <ApproveOrderModel>()
            {
                Result = this.OrderService.SearchApproveOrders(englishname, this.Member.Id)
            };

            return(response);
        }
Exemple #10
0
        public ApiListResponse <ApproveOrderModel> SummaryApproveOrders()
        {
            ApiListResponse <ApproveOrderModel> response = new ApiListResponse <ApproveOrderModel>()
            {
                Result = this.OrderService.SummaryApproveOrders(this.Member.Id)
            };

            return(response);
        }
        public ApiListResponse <RoleModel> GetAllRoles()
        {
            ApiListResponse <RoleModel> response = new ApiListResponse <RoleModel>()
            {
                Result = this.RoleService.SearchAllRole()
            };

            return(response);
        }
Exemple #12
0
        public async Task <ApiListResponse <ProviderTagDisplayModel> > Get(int skip, int limit, string languageCode, string q)
        {
            if (string.IsNullOrWhiteSpace(languageCode))
            {
                languageCode = DEFAULT_LANGUAGE_CODE;
            }
            else
            {
                languageCode = languageCode.ToLower();
            }

            if (skip < 0)
            {
                skip = 0;
            }
            if (limit < 1)
            {
                limit = 1;
            }
            if (limit > MAX_LIMIT)
            {
                limit = MAX_LIMIT;
            }

            var result = new ApiListResponse <ProviderTagDisplayModel>(skip, limit)
            {
                Data  = new List <ProviderTagDisplayModel>(),
                Total = await _providerTagRepository.Count()
            };

            var tags = (await _providerTagRepository.Search(skip, limit, q))?.ToList() ?? new List <Infrastructure.Entities.ProviderTag>();

            foreach (var tag in tags)
            {
                var name = string.Empty;
                if (tag.Translations.Any(z => z.LanguageCode == languageCode))
                {
                    name = tag.Translations.FirstOrDefault(x => x.LanguageCode == languageCode).Name;
                }
                else if (tag.Translations.Any(z => z.IsDefault))
                {
                    name = tag.Translations.FirstOrDefault(x => x.IsDefault).Name;
                }
                else
                {
                    continue;
                }

                result.Data.Add(new ProviderTagDisplayModel
                {
                    Key  = tag.Key,
                    Name = name
                });
            }

            return(result);
        }
Exemple #13
0
        public ApiListResponse <ReportModel> GetUserReports()
        {
            var response = new ApiListResponse <ReportModel>()
            {
                Result = ReportService.GetUserReports(this.Token).ToList()
            };

            return(response);
        }
Exemple #14
0
        public ApiListResponse <string> GetReportFormats()
        {
            var response = new ApiListResponse <string>()
            {
                Result = ReportService.GetReportFormats()
            };

            return(response);
        }
Exemple #15
0
        public ApiListResponse <string> GetReportParamTypes()
        {
            var response = new ApiListResponse <string>()
            {
                Result = ReportService.GetReportParameterTypes()
            };

            return(response);
        }
Exemple #16
0
        public ApiListResponse <ReportParameterModel> GetReportParameters(int reportId)
        {
            var response = new ApiListResponse <ReportParameterModel>()
            {
                Result = ReportService.GetReportParameters(reportId).ToList()
            };

            return(response);
        }
        public ApiListResponse <ProjectModel> GetAllProjects()
        {
            ApiListResponse <ProjectModel> response = new ApiListResponse <ProjectModel>()
            {
                Result = this.ProjectService.SearchAllProject()
            };

            return(response);
        }
Exemple #18
0
        public ApiListResponse <AssetTypeModel> GetAssetTypes()
        {
            var types    = this.AssetTypeService.GetAll();
            var response = new ApiListResponse <AssetTypeModel>()
            {
                Result = types
            };

            return(response);
        }
Exemple #19
0
        public ApiListResponse <BookModel> GetBookList(SearchBookModel search)
        {
            var books = this.BookService.GetBookList(search);

            var response = new ApiListResponse <BookModel>()
            {
                Result = books.ToList()
            };

            return(response);
        }
Exemple #20
0
        public ApiListResponse <BookModel> GetCurrentUserBookList()
        {
            var lsit = this.BookService.GetUserBookList(this.Member.Id);

            var response = new ApiListResponse <BookModel>()
            {
                Result = lsit.ToList()
            };

            return(response);
        }
Exemple #21
0
        public ApiListResponse <BookModel> GetUserBorrowHistory()
        {
            var list = this.BookService.GetUserBorrowedHistoryBooks(this.Member.Id);

            var response = new ApiListResponse <BookModel>()
            {
                Result = list.ToList()
            };

            return(response);
        }
        public async Task <ApiListResponse <LanguageDisplayModel> > Search(int skip, int limit, string q)
        {
            var result = new ApiListResponse <LanguageDisplayModel>(skip, limit);

            var list = await _languageRepository.Search(skip, limit, q);

            var total = await _languageRepository.Count();

            result.Data  = list?.Select(x => _mapper.Map <LanguageDisplayModel>(x)).ToList();
            result.Total = total;

            return(result);
        }
        public ApiListResponse <ExpenseMainModel> GetPendingAuditLists()
        {
            if (this.Member == null || this.Member.Id < 1)
            {
                throw new Exception("Invalid user.");
            }

            ApiListResponse <ExpenseMainModel> response = new ApiListResponse <ExpenseMainModel>()
            {
                Result = this.ExpenseService.getPendingAuditLists(this.Member.Id)
            };

            return(response);
        }
Exemple #24
0
        public ApiListResponse <OrderModel> GetPendingOrders()
        {
            if (this.Member == null || this.Member.Id < 1)
            {
                throw new Exception("Invalid user.");
            }

            ApiListResponse <OrderModel> response = new ApiListResponse <OrderModel>()
            {
                Result = this.OrderService.GetPendingOrdersByUserId(this.Member.Id)
            };

            return(response);
        }
Exemple #25
0
        public ApiListResponse <BookModel> GetUserBookList(int userId)
        {
            if (userId < 1)
            {
                throw new Exception("无效的用户ID。");
            }

            var lsit = this.BookService.GetUserBookList(userId);

            var response = new ApiListResponse <BookModel>()
            {
                Result = lsit.ToList()
            };

            return(response);
        }
Exemple #26
0
        public ApiListResponse <BookBorrowModel> GetBookBorrowHistory(int bookId)
        {
            if (bookId < 1)
            {
                throw new Exception("无效的图书ID。");
            }

            var lsit = this.BookBorrowService.GetBookBorrowHistory(bookId);

            var response = new ApiListResponse <BookBorrowModel>()
            {
                Result = lsit.ToList()
            };

            return(response);
        }
Exemple #27
0
        public ApiListResponse <AssetModel> GetMyAssets()
        {
            if (this.Member == null)
            {
                throw new Exception("当前没有授权的用户");
            }
            var assets = this.AssetService.MyList(this.Member.Id);

            HiddenAmount(assets);
            var response = new ApiListResponse <AssetModel>()
            {
                Result = assets
            };

            return(response);
        }
        public ApiListResponse <ExpenseDetailModel> GetExpenseDetail(int Id)
        {
            // 1. 验证具体请假ID
            if (Id < 1)
            {
                throw new Exception("无效的请求");
            }

            // 2. 根据报销单ID获取报销的具体信息
            var expenseDetails = this.ExpenseService.getExpenseDetailByID(Id);

            // 3. 构造 API Response 信息
            ApiListResponse <ExpenseDetailModel> response = new ApiListResponse <ExpenseDetailModel>()
            {
                Result = expenseDetails
            };

            return(response);
        }
Exemple #29
0
        public ApiListResponse <AnnouncementModel> GetPendingAnnocument()
        {
            if (this.Member == null || this.Member.Id < 1)
            {
                throw new Exception("无效的User");
            }
            RoleModel role = RoleService.SearchRole(this.Member.Role);

            if (!role.RoleName.Contains("行政"))
            {
                throw new Exception("角色为行政专员的用户才有权限操作该api");
            }
            ApiListResponse <AnnouncementModel> response = new ApiListResponse <AnnouncementModel>()
            {
                Result = this.AnnouncementService.GetPendingAnnocument()
            };

            return(response);
        }
        public ApiListResponse <MeetingCalendarModel> GetUserReserveMeetingHistory(MeetingSearchModel model)
        {
            if (model == null)
            {
                throw new ApiBadRequestException("无效请求数据");
            }
            if (model.UserId == 0)
            {
                model.UserId = this.Member.Id;
            }
            if (model.StartDate > model.EndDate)
            {
                throw new ApiBadRequestException("开始日期必须小于结束日期");
            }
            ApiListResponse <MeetingCalendarModel> response = new ApiListResponse <MeetingCalendarModel>()
            {
                Result = this.MeetingService.GetUserReserveMeetingHistory(model)
            };

            return(response);
        }