public NotificationResultDto GetNewNotifications() { var currentUserId = User.Identity.GetUserId(); var today = DateTime.Now; var userNotifications = _context.UserNotifications .Where(u => u.UserId == currentUserId); var unreadNotifications = userNotifications .Where(u => !u.IsRead) .ToList() .Count; var notifications = userNotifications .Select(u => u.Notification) .Include(n => n.Teamup.Organizer) .Where(n => DbFunctions.DiffDays(n.CreatedOn, today) <= 30) .ToList(); var notificationResultDto = new NotificationResultDto { Unread = unreadNotifications, All = notifications.Select(Mapper.Map <Notification, NotificationDto>) }; return(notificationResultDto); }
public static NotificationDto ToNotificationDto(this NotificationResultDto entity, DictionaryItemDto factorGroups) { if (entity == null) { return(null); } ShortFarmingLocationDto farmingLocation = new ShortFarmingLocationDto { Id = entity.FarmingLocationId, Name = entity.FarmingLocationName, Code = entity.FarmingLocationCode }; NotificationDto dto = new NotificationDto() { Id = entity.Id, FarmingLocation = farmingLocation, ManagementFactor = new ShortManagementFactorDto { Id = entity.ManagementFactorId, Name = entity.ManagementFactorName, Code = entity.ManagementFactorCode }, ShrimpCrop = new ShrimpCropDto { Id = entity.ShrimpCropId, Name = entity.ShrimpCropName, Code = entity.ShrimpCropCode, FromDate = entity.ShrimpCropFromDate.ToSecondsTimestamp(), ToDate = entity.ShrimpCropToDate.ToSecondsTimestamp(), FarmingLocation = farmingLocation, ShrimpBreed = new ShrimpBreedDto { Id = entity.ShrimpBreedId, Name = entity.ShrimpBreedName, Code = entity.ShrimpBreedCode, Description = entity.ShrimpBreedDescription, Attachment = entity.ShrimpBreedAttachment }, }, ExecutionTime = entity.ExecutionTime.ToSecondsTimestamp(), FromDate = entity.FromDate.ToSecondsTimestamp(), ToDate = entity.ToDate.ToSecondsTimestamp(), Status = entity.Status, CreatedAt = DateTime.UtcNow.ToSecondsTimestamp(), Type = entity.Type.ToDictionaryItemDto <NotifyType>(), Frequency = entity.Frequency.ToDictionaryItemDto <ShrimpCropFrequency>(), FactorGroup = factorGroups, }; return(dto); }
protected new IActionResult Response(NotificationResultDto resultDto) => resultDto.Sucess ? (IActionResult)Ok(resultDto) : (IActionResult)BadRequest(resultDto);