Beispiel #1
0
        public async Task <IActionResult> Get([FromHeader] string authorization, PaginedPayload payload)
        {
            try
            {
                var userObj = await GetUserByToken(authorization);

                var decks = _repository.Where(w => !w.IsBan);

                if (!string.IsNullOrEmpty(payload.Search))
                {
                    decks = decks.Where(w => w.Name.Contains(payload.Search) || w.Tags.Contains(payload.Search));
                }

                if (!string.IsNullOrEmpty(payload.Language))
                {
                    decks = decks.Where(w => w.Language == payload.Language);
                }

                decks = decks.Where(w => w.UserId == userObj.Id).OrderBy(o => o.CreatedDate);

                var decksObjs = decks.Skip(payload.Page * 10)
                                .Take(10)
                                .AsEnumerable()
                                .Select(Map <DeckEntity, DeckProxy>);

                foreach (var item in decksObjs)
                {
                    var user = await GetUserById(authorization, item.UserId);

                    item.UserName = user.Name;
                    item.ListTags = item.Tags.Split('|');
                }

                return(Json(decksObjs));
            }
            catch (Exception e)
            {
                return(BadRequest(new ApiErrorProxy()
                {
                    Code = 99,
                    Message = e.Message
                }));
            }
        }