示例#1
0
        public ActivityFileDTO GetActivityFile(int fileId)
        {
            var activityFileEntity = _databaseContext.ActivityFiles.AsNoTracking().FirstOrDefault(f => f.Id == fileId);

            if (activityFileEntity == null)
            {
                return(null);
            }

            return(_activityFileMapper.Map(activityFileEntity));
        }
示例#2
0
        public ActivityDTO Map(Activity entity)
        {
            var dto = LoadEntityData(entity);

            if (entity.Participants != null && entity.Participants.Count > 0)
            {
                dto.Participants = entity.Participants.Select(p => _activityParticipantMapper.Map(p)).ToList();
            }
            if (entity.Files != null && entity.Files.Count > 0)
            {
                dto.Files = entity.Files.OrderByDescending(f => f.CreatedOn).Select(f => _activityFileMapper.Map(f)).ToList();
            }

            dto.ChildCount = _databaseContext.Activities.Where(a => a.ParentId == entity.Id).Count();

            if (dto.ChildCount > 0)
            {
                var lastChild = _databaseContext.Activities.AsNoTracking().Where(a => a.ParentId == entity.Id).OrderByDescending(a => a.ModifiedOn).Take(1).FirstOrDefault();
                if (lastChild != null)
                {
                    var lastUserName = string.Empty;
                    if (lastChild.OwningUserId > 0)
                    {
                        var lastUser = _membershipService.GetUserEntity(lastChild.OwningUserId, true);
                        if (lastUser != null)
                        {
                            lastUserName = lastUser.Name;
                        }
                    }
                    dto.LastMessage = string.Format("{0}({1}):{2}", lastUserName, lastChild.ModifiedOn.ToLocalTime().ToString(), lastChild.Detail);
                }
            }

            if (entity.Reads != null && entity.Reads.Count > 0)
            {
                dto.IsRead = entity.Reads.Any(p => p.UserId == _workContext.CurrentUser.Id && p.Read == true);
            }

            if (entity.OwningUserId > 0)
            {
                var user = _membershipService.GetUserEntity(entity.OwningUserId, true);
                if (user != null)
                {
                    dto.OwningUserName = user.Name;
                }
            }
            return(dto);
        }