protected override async Task <IQueryable <GetModulesResult> > BuildQueryAsync(GetModulesQuery query, RequestContextCore context) { var moduleQuery = Data.Module.AsQueryable(); if (!string.IsNullOrEmpty(query.ApplicationName)) { moduleQuery = moduleQuery.Where(w => w.Application.ShortName.Contains(query.ApplicationName) || w.Application.FullName.Contains(query.ApplicationName)); } if (!string.IsNullOrEmpty(query.ModuleName)) { moduleQuery = moduleQuery.Where(w => w.Name.Contains(query.ModuleName)); } return(moduleQuery.Select(s => new GetModulesResult { ApplicationFullName = s.Application.FullName, ApplicationShortName = s.Application.ShortName, ApplicationId = s.ApplicationId, Id = s.Id, Name = s.Name })); }
protected override async Task <bool> TryBuildCommand(ICommandUpdateCore <TMolde> command, RequestContextCore Context) { var oldEntity = await GetOldEntityAsync(command); if (oldEntity == null) { command.Messages.Add(Constants.CommonMessages.THE_ITEM_DOES_NOT_EXIST); return(false); } var newEntity = await CreateNewEntityAsync(oldEntity, command); Entity.UpdateWithContext(Context, newEntity); if (command.Model is INotifiable) { var notifyobject = (INotifiable)command.Model; command.Notifications.Add(notifyobject.Notification); } return(true); }
protected override async Task <IQueryable <ApplicationModel> > BuildQueryAsync(GetApplicationsQuery query, RequestContextCore context) { var applicationQuery = Data.Application.AsQueryable(); if (!string.IsNullOrEmpty(query.ApplicationName)) { applicationQuery.Where(w => w.ShortName.Contains(query.ApplicationName) || w.FullName.Contains(query.ApplicationName)); } return(applicationQuery.ProjectTo <ApplicationModel>(_mapper.ConfigurationProvider)); }
protected override async Task <IQueryable <ResoureEntryModel> > BuildQueryAsync(GetTranslationsQuery query, RequestContextCore context) { if (string.IsNullOrEmpty(query.Application)) { return(null); } var moduleMapLanguage = Data.ModuleResource.AsQueryable(); if (!string.IsNullOrEmpty(query.Module)) { var moduleId = Data.Module.Where(w => w.Application.ShortName == query.Application && w.Name == query.Module).Select(s => s.Id).FirstOrDefault(); moduleMapLanguage = moduleMapLanguage.Where(w => w.ModuleId == moduleId); } else { var applicationId = Data.Application.Where(w => w.ShortName == query.Application) .Select(s => s.Id).FirstOrDefault(); moduleMapLanguage = moduleMapLanguage.Where(w => w.Module.ApplicationId == applicationId); } var translation = Data.Translation.AsQueryable(); if (!string.IsNullOrEmpty(query.Culture)) { var languageId = Data.Culture.Where(w => w.Code == query.Culture).Select(s => s.Id).FirstOrDefault(); translation = translation.Where(w => w.CultureId == languageId); } var dataQuery = from map in moduleMapLanguage join tran in translation on map.Baseline.Id equals tran.ResourceDefault.Id into tmpBaseline from trans in tmpBaseline.DefaultIfEmpty() select new ResoureEntryModel { Name = map.Baseline.Name, Value = trans == null ? map.Baseline.Value : trans.Display, Culture = trans == null ? "default" : trans.Culture.Code }; return(dataQuery); }
protected override async Task <IQueryable <MasterDataCategoryResult> > BuildQueryAsync(GetMasterDataCategoriesQuery query, RequestContextCore context) { var dataQuery = Entities.AsQueryable(); if (!string.IsNullOrEmpty(query.Name)) { dataQuery = dataQuery.Where(w => w.Name.Contains(query.Name)); } if (!string.IsNullOrEmpty(query.Description)) { dataQuery = dataQuery.Where(w => w.Description.Contains(query.Description)); } return(dataQuery.Select(s => new MasterDataCategoryResult { Id = s.Id, Description = s.Description, Name = s.Name })); //return dataQuery.ProjectTo<MasterDataCategoryResult>(_mapper); }
protected override async Task <bool> TryBuildCommand(ICommandRemoveCore command, RequestContextCore Context) { var oldEntity = await Entity.FindAsync(command.Id); if (oldEntity != null) { Entity.Remove(oldEntity); } return(true); }
// // Summary: // Requires derived class to implement this function. // Derived class will implement this function to build query. // Return: // System.Boolean is build query success or not. protected abstract Task <IQueryable <TResponse> > BuildQueryAsync(TQuery query, RequestContextCore context);
// // Summary: // This function for Handling a request to get list of items. // Checks is build command(s) success or not then execute the command(s) // Return: // Petronas.Core.Domain.ResultBases.IResultBase<PagedResult<TResultType>>. // With this result can be known the request is handled success or not. // And the result also contain message(s) if gets error(s). // TResultType: type of item will be get list. // Petronas.Core.Domain.ResultBases.PagedResult<T> will provide information about the list as list items, // total items. protected sealed async override Task <IResultCore <PagedResultCore <TResponse> > > Handle(TQuery query, RequestContextCore context) { var result = new ResultCore <PagedResultCore <TResponse> > { Success = true, Result = new PagedResultCore <TResponse>() }; var queryable = await BuildQueryAsync(query, context); if (queryable == null) { result.Success = false; result.ErrorMessages = query.Messages; return(result); } result.Result.TotalRow = queryable.Count(); if (!string.IsNullOrEmpty(query.OrderBy)) { queryable = queryable.OrderBy(query.OrderBy, query.OrderByDirection); } if (query.IsPaged) { result.Result.Skip = query.Skip; result.Result.Take = query.Take; queryable = queryable.Skip(query.Skip).Take(query.Take); } result.Success = true; result.Result.Result = await queryable.ToListAsync(); return(result); }
protected override async Task <IQueryable <QuestionCategoryModel> > BuildQueryAsync(GetQuestionCategoriesQuery query, RequestContextCore context) { var applicationQuery = Data.QuestionCategory.AsQueryable(); if (!string.IsNullOrEmpty(query.Name)) { applicationQuery.Where(w => w.Name.Contains(query.Name)); } if (!string.IsNullOrEmpty(query.Desctiption)) { applicationQuery.Where(w => w.Desctiption.Contains(query.Desctiption)); } return(applicationQuery.ProjectTo <QuestionCategoryModel>(_mapper.ConfigurationProvider)); }