Ejemplo n.º 1
0
 private void MapEntityToModel(Being entity, BeingListModel model)
 {
     model.Id     = entity.Id;
     model.UserId = entity.UserId;
     model.Name   = entity.Name;
     model.Icon   = entity.Icon;
 }
Ejemplo n.º 2
0
        public async Task <ActionResult <List <BeingListModel> > > GetList()
        {
            string userId = HttpContext.User.FindUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }

            List <Being> entities = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Beings, userId)
                                    .OrderBy(b => b.Name)
                                    .ToListAsync();

            List <BeingListModel> models = new List <BeingListModel>();

            foreach (Being entity in entities)
            {
                var model = new BeingListModel();
                models.Add(model);

                MapEntityToModel(entity, model);

                int entries = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Entries, userId)
                              .Where(e => e.Beings.Contains(entity))
                              .CountAsync();

                model.Entries = entries;
            }

            var userNames = await this.userNames.GetUserNamesAsync(models.Select(e => e.UserId).ToArray());

            for (int i = 0; i < models.Count; i++)
            {
                models[i].UserName = userNames[i];
            }

            return(Ok(models));
        }