public async Task SendOrderReciveNotifcation(IEnumerable <Order> orders) { var moneyPlacedes = await _uintOfWork.Repository <MoenyPlaced>().GetAll(); var outSideCompny = moneyPlacedes.First(c => c.Id == (int)MoneyPalcedEnum.OutSideCompany).Name; List <Notfication> totalNotfications = new List <Notfication>(); List <Notfication> detailNotifications = new List <Notfication>(); foreach (Order order in orders) { if (order.OrderStateId != (int)OrderStateEnum.Finished && order.OrderplacedId != (int)OrderplacedEnum.Way) { var clientNotigaction = totalNotfications.Where(c => c.ClientId == order.ClientId && c.OrderPlacedId == order.OrderplacedId && c.MoneyPlacedId == order.MoenyPlacedId).FirstOrDefault(); if (clientNotigaction == null) { int moenyPlacedId = order.MoenyPlacedId; if (moenyPlacedId == (int)MoneyPalcedEnum.WithAgent) { moenyPlacedId = (int)MoneyPalcedEnum.OutSideCompany; } clientNotigaction = new Notfication() { ClientId = order.ClientId, OrderPlacedId = order.OrderplacedId, MoneyPlacedId = moenyPlacedId, IsSeen = false, OrderCount = 1 }; totalNotfications.Add(clientNotigaction); } else { clientNotigaction.OrderCount++; } } var moneyPlacedName = order.MoenyPlaced.Name; if (order.MoenyPlacedId == (int)MoneyPalcedEnum.WithAgent) { moneyPlacedName = outSideCompny; } detailNotifications.Add(new Notfication() { Note = $"الطلب {order.Code} اصبح {order.Orderplaced.Name} و موقع المبلغ {order.MoenyPlaced.Name}", ClientId = order.ClientId }); } await _uintOfWork.AddRange(detailNotifications); await _uintOfWork.AddRange(totalNotfications); var unionNotification = totalNotfications.Union(detailNotifications); var grouping = unionNotification.GroupBy(c => c.ClientId); foreach (var item in grouping) { var key = item.Key.ToString(); var notficationDtos = item.Select(c => _mapper.Map <NotificationDto>(c)); await _notificationHub.AllNotification(key.ToString(), notficationDtos.ToArray()); } }
public async Task <IActionResult> GetNo() { var uId = AuthoticateUserId(); var nos = await this._context.Notfications.Where(c => c.ClientId == uId && c.IsSeen == false) .Include(c => c.MoneyPlaced) .Include(c => c.OrderPlaced) .ToListAsync(); var dto = _mapper.Map <NotificationDto[]>(nos); await notificationHub.AllNotification(AuthoticateUserId().ToString(), dto); return(Ok()); }