Beispiel #1
0
        public IEnumerable <SpaceListItem> GetAllSpaces(SpaceSearchParams model)
        {
            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var spaces = ctx.Spaces.AsQueryable();

                    if (model.ShowOnlyVacant)
                    {
                        spaces = spaces.Where(s => s.Status == "vacant");
                    }

                    if (model.ShowByOwner && model.OwnerId != null)
                    {
                        spaces = spaces.Where(s => s.OwnerId == model.OwnerId);
                    }

                    return(spaces.Select(s => new SpaceListItem
                    {
                        Category = s.Category.Name,
                        Status = s.Status,
                        CreatedAt = s.CreatedAt,
                        Id = s.Id,
                        Name = s.Name
                    }).ToList());
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(null);
            }
        }
Beispiel #2
0
        public IHttpActionResult Get([FromUri] SpaceSearchParams searchParams)
        {
            var response = _service.GetAllSpaces(searchParams);

            if (response == null)
            {
                return(NotFound());
            }
            return(Ok(response));
        }