Exemplo n.º 1
0
        public async Task <NotedObjectUnitListDto> GetNotedObjectUnit(GetNotedObjectUnitInput input)
        {
            NotedObjectUnitListDto notedObjectUnitListDto = new NotedObjectUnitListDto();

            notedObjectUnitListDto.NotedObjectUnitDto = new List <NotedObjectUnitDto>();

            var notedObjectUnitList = await(from note in _notedObjectUnitRepository.GetAll()
                                            join user in _userUnitRepository.GetAll() on note.CreatorUserId equals user.Id into notes
                                            from noteinner in notes.DefaultIfEmpty()
                                            where note.TypeOfObjectId == input.TypeOfObjectId && note.ObjectId == input.ObjectId
                                            select new { note, noteinner.UserName }).ToListAsync();

            if (notedObjectUnitList.Any())
            {
                foreach (var item in notedObjectUnitList)
                {
                    NotedObjectUnitDto notedObjectUnitDto = new NotedObjectUnitDto();
                    notedObjectUnitDto.NotedObjectId = item.note.Id;
                    notedObjectUnitDto.CreatedUser   = item.UserName;
                    notedObjectUnitDto.CreationTime  = item.note.CreationTime;

                    Mapper.Map(item.note, notedObjectUnitDto);
                    notedObjectUnitListDto.NotedObjectUnitDto.Add(notedObjectUnitDto);
                }
            }

            return(notedObjectUnitListDto);
        }
Exemplo n.º 2
0
        public async Task <List <NotedObjectUnitDto> > GetNotedObjectForRavi(GetNotedObjectUnitInput input)
        {
            var notedObjectUnitList = from note in _notedObjectUnitRepository.GetAll()
                                      join user in _userUnitRepository.GetAll() on note.CreatorUserId equals user.Id into notes
                                      from noteinner in notes.DefaultIfEmpty()
                                      where note.TypeOfObjectId == input.TypeOfObjectId && note.ObjectId == input.ObjectId
                                      select new
            {
                NotedObjectId  = note.Id,
                Notes          = note.Notes,
                CreatedUser    = noteinner.UserName,
                TypeOfObjectId = note.TypeOfObjectId,
                ObjectId       = note.ObjectId,
                CreationTime   = note.CreationTime,
                CreatedUserId  = note.CreatorUserId
            };
            var result = await notedObjectUnitList.OrderBy(Helper.GetSort("CreationTime DESC", "")).ToListAsync();//

            return(new List <NotedObjectUnitDto>(result.Select(item =>
            {
                var dto = item.MapTo <NotedObjectUnitDto>();
                dto.CreationTime = item.CreationTime;
                //TODO:change based on history tracking. Make sure user only can edit/delete his own added notes.
                if (item.CreatedUserId > 0)//TODO:&&item.CreatedUserId===CurrentLogin userId.
                {
                    dto.AllowEdit = true;
                    dto.AllowDelete = true;
                    dto.CreatedUser = item.CreatedUser;
                }
                else
                {
                    dto.AllowEdit = false;
                    dto.AllowDelete = false;
                    dto.CreatedUser = "******";
                }

                return dto;
            })));
        }