public async Task <IActionResult> PushNotificationList(PushNotificationSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePushNotification)) { return(AccessDeniedKendoGridJson()); } var model = await _pushNotificationModelFactory.PreparePushNotificationListModel(searchModel); return(Json(model)); }
public async Task <PushNotificationListModel> PreparePushNotificationListModel(PushNotificationSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var pushNotifications = await _pushNotificationService.GetPushNotificationsAsync( storeIds : searchModel.SelectedStoreIds.ToArray(), pushCategoryIds : searchModel.SelectedNotificationCategoryIds.ToArray(), title : searchModel.SearchTitle, desc : searchModel.SearchDesc, stNo : searchModel.SearchStockTakeNo, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); var model = new PushNotificationListModel { Data = pushNotifications.Select(pushNotification => { var pushNotificationsModel = pushNotification.ToModel <PushNotificationModel>(); pushNotificationsModel.Title = pushNotification.Title; pushNotificationsModel.Description = pushNotification.Desc; pushNotificationsModel.StockTakeNo = pushNotification.StockTakeNo; pushNotificationsModel.CategoryName = pushNotification.NotificationCategory?.Name; if (pushNotificationsModel.StockTakeNo != 0) { pushNotificationsModel.StoreName = GetStockTakeStore(pushNotificationsModel.StockTakeNo); pushNotificationsModel.CategoryName += " (" + pushNotificationsModel.StockTakeNo + ")"; } else { pushNotificationsModel.StoreName = String.Join(", ", pushNotification.PushNotificationStores.Select(store => store.Store.P_BranchNo + " - " + store.Store.P_Name)); } pushNotificationsModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(pushNotification.CreatedOnUtc, DateTimeKind.Utc); pushNotificationsModel.LastActivityDate = _dateTimeHelper.ConvertToUserTime(pushNotification.ModifiedOnUtc.GetValueOrDefault(DateTime.UtcNow), DateTimeKind.Utc); return(pushNotificationsModel); }), Total = pushNotifications.TotalCount }; // sort if (searchModel.Sort != null && searchModel.Sort.Any()) { foreach (var s in searchModel.Sort) { model.Data = await model.Data.Sort(s.Field, s.Dir); } } // filter if (searchModel.Filter != null && searchModel.Filter.Filters != null && searchModel.Filter.Filters.Any()) { var filter = searchModel.Filter; model.Data = await model.Data.Filter(filter); model.Total = model.Data.Count(); } return(model); }
public async Task <PushNotificationSearchModel> PreparePushNotificationSearchModel(PushNotificationSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare page parameters searchModel.SetGridPageSize(); var stores = await _storeService.GetStores(); searchModel.AvailableStores = stores.Select(store => new SelectListItem { Text = store.P_BranchNo.ToString() + " - " + store.P_Name, Value = store.P_BranchNo.ToString() }).ToList(); SelectListItem initialItem = new SelectListItem() { Text = "ALL", Value = "-99" }; searchModel.AvailableStores.Insert(0, initialItem); var notificationCategories = await _pushNotificationService.GetNotificationCategoriesAsync(); //TODO //if (notificationCategories != null && notificationCategories.Count > 0) //{ // _pushNotificationService. //} //else //{ //} searchModel.AvailableNotificationCategory = notificationCategories.Select(notificationCategory => new SelectListItem { Text = notificationCategory.Name, Value = notificationCategory.Id.ToString() }).ToList(); return(await Task.FromResult(searchModel)); }