public static async Task <G> GetFreeResultAsync <T, G>(UserService userService, ItemDataModel itemDataModel, IItemRepository itemRepository) where T : FreeBusinessModel where G : GetFreeResult, new() { var moduleFree = (T)itemDataModel.Data; var userInfo = await GetFreeCommand.GetUserInfoAsync <T>(userService, moduleFree); var result = new G(); result.Elements = await GetNewsCommand.UpdateElementAsync(itemDataModel.SiteId, moduleFree.Elements, itemRepository); result.UserInfo = userInfo.UserInfo; result.LastUpdateUserInfo = userInfo.LastUpdateUserInfo; result.CreateDate = itemDataModel.CreateDate; result.UpdateDate = itemDataModel.UpdateDate; return(result); }
protected override async Task ActionAsync() { var siteId = Input.SiteId; var itemDataModel = await GetAsync <NotificationBusinessModel>(siteId, siteId, NotificationBusinessModule.ModuleName, "Notification"); if (itemDataModel == null) { Result.ValidationResult.AddError("NO_DATA_FOUND"); return; } /* var moduleNews = (NewsBusinessModel)itemDataModel.Data; * GetNewsCommand. UpdateElementAsync(moduleNews.Elements); * var userInfo = await GetFreeCommand.GetUserInfoAsync(_userService, moduleNews);*/ int nbChild = 20; Func <ItemDataModel, Task <GetNewsItemSummary> > getItemFunc = GetItemsAsync <GetNewsItemSummary, NotificationItemBusinessModel>; var newsItemResult = await GetNewsCommand.GetNewsItemSummariesAsync(_dataFactory, Input, nbChild, itemDataModel, getItemFunc); var result = new GetNewsResult(); result.NumberItemPerPage = nbChild; /* result.Elements = moduleNews.Elements; * * result.DisplayMode = moduleNews.DisplayMode; * result.UserInfo = userInfo.UserInfo; * result.LastUpdateUserInfo = userInfo.LastUpdateUserInfo;*/ result.CreateDate = itemDataModel.CreateDate; result.UpdateDate = itemDataModel.UpdateDate; result.GetNewsItem = newsItemResult.Items; result.HasNext = newsItemResult.HasNext; result.IdNext = newsItemResult.IdNext; result.HasPrevious = newsItemResult.HasPrevious; result.IdPrevious = newsItemResult.IdPrevious; result.ModuleId = itemDataModel.Id; Result.Data = result; }
private async Task <T> GetItemsAsync <T, G>(ItemDataModel dataModel) where T : GetNewsItemSummary, new() where G : NotificationItemBusinessModel, new() { var newsItem = dataModel.Data as G; if (newsItem != null) { var userInfoNewsItem = await GetFreeCommand.GetUserInfoAsync(_userService, newsItem); var getNewsItemResult = new T(); var elements = newsItem.Elements; await GetNewsCommand.UpdateElementAsync(dataModel.SiteId, elements, _dataFactory.ItemRepository); getNewsItemResult.Elements = elements; getNewsItemResult.ModuleId = dataModel.Id; getNewsItemResult.CreateDate = dataModel.CreateDate; getNewsItemResult.UpdateDate = dataModel.UpdateDate; getNewsItemResult.UserInfo = userInfoNewsItem.UserInfo; getNewsItemResult.LastUpdateUserInfo = userInfoNewsItem.LastUpdateUserInfo; return(getNewsItemResult); } return(null); }
public async Task <CommandResult> Get([FromServices] GetNewsCommand _getNewsCommand, string siteId, string moduleId, IList <ItemState> states = null, int?index = null, string[] tags = null) { var input = new UserInput <GetNewsInput> { Data = new GetNewsInput { ModuleId = moduleId, SiteId = siteId, FilterIndex = index, States = states, Tags = tags == null ? null : new List <string>(tags.Where(t => t != null && t != "null" && !string.IsNullOrEmpty(t))) }, UserId = User.Identity.IsAuthenticated ? User.GetUserId() : string.Empty }; var result = await Business .InvokeAsync <GetNewsCommand, UserInput <GetNewsInput>, CommandResult <GetNewsResult> >(_getNewsCommand, input).ConfigureAwait(false); return(result); }