示例#1
0
        public HousesResponseModel Get()
        {
            //could use automapper here, bit annoying 

            var username = GetUserName();

            var houses = _houseContext.Houses.Select(h => new HouseResponseModel
            {
                Id = h.ID,
                Accepted = h.Accepted,
                AcceptedOffer = h.AcceptedOffer,
                Description = h.Description,
                Listed = h.Listed,
                Owner = h.Owner,
                Title = h.Title,
                Offers = h.Offers.Where(o => o.Buyer == username).ToList(), //need to filter by current user, don't want to see other offers!
                Value = h.Value 
            });

            var result = new HousesResponseModel {Results = houses};
            return result;
        }
示例#2
0
        public HousesResponseModel OwnerHouses()
        {
            var name = GetUserName();
            var sellersHouses = _houseContext.Houses.Select(h => new HouseResponseModel
            {
                Id = h.ID,
                Accepted = h.Accepted,
                AcceptedOffer = h.AcceptedOffer,
                Description = h.Description,
                Listed = h.Listed,
                Owner = h.Owner,
                Title = h.Title,
                Offers = h.Offers,
                Value =  h.Value
            }).Where(h => h.Owner == name);

            var response = new HousesResponseModel {Results = sellersHouses.ToList()};
            return response;
        }