public async Task <IDataSourceResult <ActivityLog> > GetActivityLogsAsync( int skip, int take, string ipAddress = "", string message = "", string userId = null, ActivityTypeEnum?activityType = null, DateTime?startCreatedTime = null, DateTime?endCreatedTime = null) { BaseSpecification <ActivityLog> activityLogSpecification = new BaseSpecification <ActivityLog>(q => (string.IsNullOrEmpty(message) || EF.Functions.Contains(q.Message, message)) && (string.IsNullOrEmpty(userId) || q.UserId == userId) && (string.IsNullOrEmpty(ipAddress) || q.IpAddress == ipAddress) && (!startCreatedTime.HasValue || q.CreatedTime >= startCreatedTime) && (!endCreatedTime.HasValue || q.CreatedTime <= endCreatedTime) && (!activityType.HasValue || q.Type == activityType)); activityLogSpecification.ApplyOrderByDescending(q => q.Id); activityLogSpecification.ApplySelector(q => new ActivityLog { Id = q.Id, CreatedTime = q.CreatedTime, UserId = q.UserId, Message = q.Message, Type = q.Type, ObjectType = q.ObjectType, IpAddress = q.IpAddress, Complete = q.Complete }); activityLogSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(activityLogSpecification)); }
public static BaseSpecification <TodoItem> NameStartWith(string name, int skip, int take) { var spec = new BaseSpecification <TodoItem>(t => t.Name.Contains(name)); spec.ApplyOrderBy(t => t.Name); spec.ApplyPaging(skip, take); return(spec); }
/// <summary> /// Hàm lấy danh sách giá trị config hệ thống theo key /// </summary> /// <param name="skip">Số bản ghi bỏ qua</param> /// <param name="take">Số bản ghi cần lấy</param> /// <param name="key">Key code</param> /// <returns>IDataSourceResult</returns> public async Task <IDataSourceResult <SystemValue> > GetSystemValuesAsync(int skip, int take, string key = "") { BaseSpecification <SystemValue> systemValueSpecification = new BaseSpecification <SystemValue>(q => (string.IsNullOrEmpty(key) || EF.Functions.Contains(q.Key, key))); systemValueSpecification.ApplyOrderByDescending(q => q.Id); systemValueSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(systemValueSpecification)); }
public async Task <IDataSourceResult <UserGroup> > GetUserGroupsAsync(int skip, int take, string name = "") { BaseSpecification <UserGroup> baseSpecification = new BaseSpecification <UserGroup>(q => (string.IsNullOrEmpty(name) || q.Name.Contains(name))); baseSpecification.ApplyOrderBy(q => q.DisplayOrder); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
/// <summary> /// Lấy danh sách UserGroupMapping /// </summary> /// <param name="skip">skip row value</param> /// <param name="take">take row value</param> /// <param name="userId">Id người dùng</param> /// <param name="groupId">Id ngóm</param> /// <returns>Danh sách mapping</returns> public async Task <IDataSourceResult <UserGroupMapping> > GetUserGroupMappingsAsync(int skip, int take, string userId = null, string groupId = null) { BaseSpecification <UserGroupMapping> baseSpecification = new BaseSpecification <UserGroupMapping>(q => (string.IsNullOrEmpty(userId) || q.UserId == userId) && (string.IsNullOrEmpty(groupId) || q.UserGroupId == groupId)); baseSpecification.ApplyOrderByDescending(q => q.Id); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
public async Task <IEnumerable <Todo> > GetTodosAsync(int start, int pageSize, Guid userId) { if (userId == default(Guid)) { throw new ArgumentException($"{nameof(userId)} 错误"); } var specification = new BaseSpecification <Todo>(c => c.Creator == userId); specification.ApplyPaging(start, pageSize); return(await _todoRepository.GetTodosAsync(specification)); }
public async Task <IDataSourceResult <ScheduleTask> > GetScheduleTasksAsync(int skip, int take, string name = "", ScheduleType?type = null, bool?enabled = null, bool?stopOnError = null) { BaseSpecification <ScheduleTask> baseSpecification = new BaseSpecification <ScheduleTask>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (!type.HasValue || q.Type == type) && (!enabled.HasValue || q.Enabled == enabled) && (!stopOnError.HasValue || q.StopOnError == stopOnError)); baseSpecification.ApplyOrderByDescending(q => q.Id); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
public async Task <IDataSourceResult <FileResourceMapping> > GetMediaMappingsAsync(int skip, int take, string fileResourceId = null, string objectId = null, ObjectTypeEnum?objectTypeId = null, bool?published = null) { BaseSpecification <FileResourceMapping> baseSpecification = new BaseSpecification <FileResourceMapping>(q => (!published.HasValue || q.Published == published) && (!objectTypeId.HasValue || q.ObjectType == objectTypeId) && (string.IsNullOrEmpty(objectId) || q.ObjectId == objectId) && (string.IsNullOrEmpty(fileResourceId) || q.FileResourceId == fileResourceId)); baseSpecification.ApplyOrderBy(q => q.DisplayOrder); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
public async Task <IDataSourceResult <CmsMenu> > GetMenusAsync(int skip, int take, string position = "", bool?active = null, string name = null, string parentId = null) { BaseSpecification <CmsMenu> menuSpecification = new BaseSpecification <CmsMenu>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (string.IsNullOrEmpty(position) || EF.Functions.Contains(q.Position, position)) && (string.IsNullOrEmpty(parentId) || q.ParentId == parentId) && (!active.HasValue || q.Active == active)); menuSpecification.ApplyOrderBy(q => q.DisplayOrder); menuSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(menuSpecification)); }
public virtual async Task <IDataSourceResult <EmailAccount> > GetEmailAccountsAsync(int skip, int take, bool?useDefault = null, string name = "", string email = "", string host = "", string userName = "", int?port = null) { BaseSpecification <EmailAccount> emailAccountSpecification = new BaseSpecification <EmailAccount>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (string.IsNullOrEmpty(email) || q.Email == email) && (string.IsNullOrEmpty(host) || q.Host == host) && (string.IsNullOrEmpty(userName) || q.UserName == userName) && (!useDefault.HasValue || q.UseDefault == useDefault) && (!port.HasValue || q.Port == port)); emailAccountSpecification.ApplyOrderByDescending(q => q.Id); emailAccountSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(emailAccountSpecification)); }
public async Task <IList <ResponsibleResponseTO> > ListAsync(ResponsibleFilterTO filterTO) { var responsibleSpecification = new BaseSpecification <ResponsibleEntity>(); responsibleSpecification.AddCriteria(filterTO.UnifiedProcessNumber, responsible => responsible.ProcessResponsible.Any(processResponsible => processResponsible.Process != null && !string.IsNullOrEmpty(processResponsible.Process.UnifiedProcessNumber) && processResponsible.Process.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty).Contains(filterTO.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty)))); responsibleSpecification.AddCriteria(filterTO.Cpf, responsible => responsible.Cpf == Convert.ToInt64(filterTO.Cpf.Replace(".", string.Empty).Replace("-", string.Empty))); responsibleSpecification.AddCriteria(filterTO.Name, responsible => responsible.Name.Trim().ToUpper().Contains(filterTO.Name.Trim().ToUpper())); responsibleSpecification.ApplyOrderByDescending(responsible => responsible.Name); responsibleSpecification.ApplyPaging(filterTO.Page.GetValueOrDefault(), filterTO.PerPage.GetValueOrDefault()); var listResponsible = await _responsibleRepository.ListAsync(responsibleSpecification); return(listResponsible.ToList().ToListResponsibleResponseTO()); }
public async Task <IDataSourceResult <LanguageResource> > GetLanguageResources( int skip, int take, string culture = null, string key = null, string value = null) { BaseSpecification <LanguageResource> baseSpecification = new BaseSpecification <LanguageResource>(q => (string.IsNullOrEmpty(value) || EF.Functions.Contains(q.Value, value)) && (string.IsNullOrEmpty(key) || q.Key == key) && (string.IsNullOrEmpty(culture) || q.Culture == culture)); baseSpecification.ApplyOrderByDescending(q => q.Id); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
public async Task <IDataSourceResult <Language> > GetLanguagesAsync( int skip, int take, string name = "", bool?published = null, bool?displayDefault = null) { BaseSpecification <Language> baseSpecification = new BaseSpecification <Language>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (!displayDefault.HasValue || q.DisplayDefault == displayDefault) && (!published.HasValue || q.Published == published)); baseSpecification.ApplyOrderByDescending(q => q.Id); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
public virtual async Task <IDataSourceResult <MessageTemplate> > GetMessageTemplatesAsync(int skip, int take, string name = "", string title = "") { BaseSpecification <MessageTemplate> messageTemplateSpecification = new BaseSpecification <MessageTemplate>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (string.IsNullOrEmpty(title) || EF.Functions.Contains(q.Title, title))); messageTemplateSpecification.ApplyOrderByDescending(q => q.Id); messageTemplateSpecification.ApplySelector(q => new MessageTemplate() { Id = q.Id, Name = q.Name, Title = q.Title, UpdatedTime = q.UpdatedTime }); messageTemplateSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(messageTemplateSpecification)); }
public async Task <List <ReceiverViewModel> > GetReceivers(Guid currentUserId, int pageIndex) { BaseSpecification <Group> groupSpec = new BaseSpecification <Group>(); groupSpec.AddCriteria(x => x.GroupUsers.Any(y => y.UserId == currentUserId)); groupSpec.ApplyPaging(pageIndex * Constants.ItemsPerPage, Constants.ItemsPerPage); groupSpec.ApplyOrderBy(x => x.Name); IReadOnlyList <Group> groups = await _groupRepository.ListAsync(groupSpec); List <ReceiverViewModel> results = groups.Select(x => new ReceiverViewModel() { Id = x.Id, Name = x.Name, IconUrl = "https://ptetutorials.com/images/user-profile.png" //todo: need add to db }).ToList(); if (Constants.ItemsPerPage == results.Count) { return(results); } int groupCount = await _groupRepository.CountAsync(new BaseSpecification <Group>()); int gropupPage = (int)Math.Floor((decimal)(groupCount / Constants.ItemsPerPage)); pageIndex -= gropupPage; int skip = pageIndex > 0 ? (((gropupPage + 1) * Constants.ItemsPerPage) - groupCount) + ((pageIndex - 1) * Constants.ItemsPerPage) : 0; BaseSpecification <User> userSpec = new BaseSpecification <User>(); userSpec.AddCriteria(x => x.Id != currentUserId); userSpec.ApplyPaging(skip, Constants.ItemsPerPage - results.Count); userSpec.ApplyOrderBy(x => x.Name); IReadOnlyList <User> users = await _userRepository.ListAsync(userSpec); results.AddRange(users.Select(x => new ReceiverViewModel() { Id = x.Id, Name = x.Name, IconUrl = "https://ptetutorials.com/images/user-profile.png" //todo: need add to db }).ToList()); return(results); }
public async Task <IList <ProcessResponseTO> > ListAsync(ProcessFilterTO filterTO) { var processSpecification = new BaseSpecification <ProcessEntity>(); processSpecification.AddCriteria(filterTO.UnifiedProcessNumber, process => process.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty) == filterTO.UnifiedProcessNumber.Replace("-", string.Empty).Replace(".", string.Empty)); processSpecification.AddCriteria(filterTO.DistributionDateStart, process => process.DistributionDate >= filterTO.DistributionDateStart); processSpecification.AddCriteria(filterTO.DistributionDateEnd, process => process.DistributionDate <= filterTO.DistributionDateEnd); processSpecification.AddCriteria(filterTO.JusticeSecret, process => process.JusticeSecret == filterTO.JusticeSecret); processSpecification.AddCriteria(filterTO.ClientPhysicalFolder, process => process.ClientPhysicalFolder.Trim().ToUpper().Contains(filterTO.ClientPhysicalFolder.Trim().ToUpper())); processSpecification.AddCriteria(filterTO.SituationId, process => process.SituationId == filterTO.SituationId); processSpecification.AddCriteria(filterTO.ResponsibleName, process => process.ProcessResponsible.Any(processResponsible => processResponsible.Responsible != null && !string.IsNullOrEmpty(processResponsible.Responsible.Name) && processResponsible.Responsible.Name.Trim().ToUpper().Contains(filterTO.ResponsibleName.Trim().ToUpper()))); processSpecification.ApplyOrderByDescending(responsible => responsible.UnifiedProcessNumber); processSpecification.ApplyPaging(filterTO.Page.GetValueOrDefault(), filterTO.PerPage.GetValueOrDefault()); var listProcess = await _processRepository.ListAsync(processSpecification); return(listProcess.ToList().ToListProcessResponseTO()); }
/// <summary> /// Lấy danh sách thư viên tệp tin theo nhiều tham số /// </summary> /// <param name="skip">Số bản ghi bỏ qua</param> /// <param name="take">Số bản ghi cần lấy</param> /// <param name="description">Mô tả cho file</param> /// <param name="type">Loại resource</param> /// <param name="userId">Người tạo tệp tin</param> /// <param name="startDate">Bắt đầu ngày tạo</param> /// <param name="endDate">Kết thúc ngày tạo</param> /// <returns>IDataSourceResult Media</returns> public async Task <IDataSourceResult <FileResource> > GetFileResourcesAsync( int skip, int take, string description = "", ResourceType?type = null, string userId = null, DateTime?startDate = null, DateTime?endDate = null) { BaseSpecification <FileResource> resourceSpecification = new BaseSpecification <FileResource>(q => (string.IsNullOrEmpty(description) || EF.Functions.Contains(q.Description, description)) && (string.IsNullOrEmpty(userId) || q.UserId == userId) && (!startDate.HasValue || q.CreatedTime >= startDate) && (!endDate.HasValue || q.CreatedTime <= endDate) && (!type.HasValue || q.Type == type)); resourceSpecification.ApplyOrderByDescending(q => q.Id); resourceSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(resourceSpecification)); }
public async Task <IDataSourceResult <SystemLog> > GetErrorLogsAsync( int skip, int take, LogLevel?logLevelId = null, string shortMessage = "", string ipAdress = "", DateTime?startDate = null, DateTime?endDate = null) { BaseSpecification <SystemLog> errorLogSpecification = new BaseSpecification <SystemLog>(q => (string.IsNullOrEmpty(shortMessage) || EF.Functions.Contains(q.Message, shortMessage)) && (string.IsNullOrEmpty(ipAdress) || q.IpAddress == ipAdress) && (!startDate.HasValue || q.CreatedTime >= startDate) && (!endDate.HasValue || q.CreatedTime <= endDate) && (!logLevelId.HasValue || q.Level == logLevelId)); errorLogSpecification.ApplyOrderByDescending(q => q.Id); errorLogSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(errorLogSpecification)); }
public async Task <IDataSourceResult <Currency> > GetCurrenciesAsync( int skip, int take, string name = "", string currencyCode = "", bool?published = null, bool?isPrimaryExchange = null, bool?isPrimarySystem = null) { BaseSpecification <Currency> baseSpecification = new BaseSpecification <Currency>(q => (string.IsNullOrEmpty(name) || EF.Functions.Contains(q.Name, name)) && (string.IsNullOrEmpty(currencyCode) || q.CurrencyCode == currencyCode) && (!published.HasValue || q.Published == published) && (!isPrimaryExchange.HasValue || q.IsPrimaryExchange == isPrimaryExchange) && (!isPrimarySystem.HasValue || q.IsPrimarySystem == isPrimarySystem)); baseSpecification.ApplyOrderBy(q => q.DisplayOrder); baseSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(baseSpecification)); }
/// <summary> /// Lấy email trong queued theo nhiều tham số /// </summary> /// <param name="skip">Số bản ghi bỏ qua</param> /// <param name="take">Số bản ghi cần lấy</param> /// <param name="title">Tiêu đề email</param> /// <param name="to">Gửi đến</param> /// <param name="submitted">Đã gửi hay chưa</param> /// <param name="emailAccouantId">Tài khoản gửi. Chỉ có khi đã gửi</param> /// <param name="fromDate">Từ Ngày tạo email trong queued</param> /// <param name="toDate">Đến Ngày tạo email trong queued</param> /// <returns>Task IDataSourceResult QueuedEmail</returns> public virtual async Task <IDataSourceResult <QueuedEmail> > GetQueuedEmailsAsync( int skip, int take, string title = "", string toEmail = "", bool?submitted = null, string emailAccouantId = null, DateTime?fromDate = null, DateTime?toDate = null) { BaseSpecification <QueuedEmail> queuedEmailSpecification = new BaseSpecification <QueuedEmail>(q => (string.IsNullOrEmpty(title) || EF.Functions.Contains(q.Title, title)) && (string.IsNullOrEmpty(toEmail) || q.To == toEmail) && (!submitted.HasValue || (submitted == true && q.SendTime != null) || (submitted != true && q.SendTime == null)) && (string.IsNullOrEmpty(emailAccouantId) || q.EmailAccountId == emailAccouantId) && (!fromDate.HasValue || q.CreatedTime >= fromDate) && (!toDate.HasValue || q.CreatedTime <= toDate)); queuedEmailSpecification.ApplyOrderByDescending(q => q.Id); queuedEmailSpecification.ApplyPaging(skip, take); return(await ToDataSourceResultAsync(queuedEmailSpecification)); }
public async Task <IDataSourceResult <User> > GetUsersAsync( int skip, int take, string groupId = null, string email = null, string userName = null, string displayName = null, bool?active = null, Gender?gender = null, string languageCulture = null, string currencyCulture = null, DateTime?fromBirthDay = null, DateTime?toBirthDay = null, DateTime?fromLastLoginTime = null, DateTime?toLastLoginTime = null, DateTime?fromCreatedTime = null, DateTime?toCreatedTime = null) { IQueryable <User> userQuery = DbContext.Set <User>().AsNoTracking(); if (!string.IsNullOrEmpty(groupId)) { IQueryable <UserGroupMapping> mappingQuery = DbContext.Set <UserGroupMapping>().Where(q => q.UserGroupId == groupId); userQuery = from user in userQuery join mapping in mappingQuery on user.Id equals mapping.UserId where mapping.UserGroupId == groupId select user; } BaseSpecification <User> baseSpecification = new BaseSpecification <User>(q => !q.Deleted && (string.IsNullOrEmpty(userName) || q.UserName.Contains(userName)) && (string.IsNullOrEmpty(displayName) || q.DisplayName.Contains(displayName)) && (string.IsNullOrEmpty(email) || q.Email == email) && (string.IsNullOrEmpty(languageCulture) || q.LanguageCulture == languageCulture) && (string.IsNullOrEmpty(currencyCulture) || q.CurrencyCode == currencyCulture) && (!active.HasValue || q.Active == active) && (!gender.HasValue || q.Gender == gender) && (!fromBirthDay.HasValue || q.BirthDay >= fromBirthDay) && (!toBirthDay.HasValue || q.BirthDay <= toBirthDay) && (!fromLastLoginTime.HasValue || q.LastLoginTime >= fromLastLoginTime) && (!toLastLoginTime.HasValue || q.LastLoginTime <= toLastLoginTime) && (!fromCreatedTime.HasValue || q.CreatedTime >= fromCreatedTime) && (!toCreatedTime.HasValue || q.CreatedTime <= toCreatedTime)); baseSpecification.ApplyOrderByDescending(q => q.CreatedTime); baseSpecification.ApplySelector(x => new User { Id = x.Id, AvatarImage = x.AvatarImage, Email = x.Email, DisplayName = x.DisplayName, Active = x.Active, CreatedTime = x.CreatedTime, UpdatedTime = x.UpdatedTime, LastLoginTime = x.LastLoginTime }); baseSpecification.ApplyPaging(skip, take); return(await userQuery.ToDataSourceResultAsync(baseSpecification)); }