static void Main(string[] args)
        {
            RealEstateAgent immo = new RealEstateAgent();

            Appartment app1 = new Appartment("Appartementstraat 10", 1, 180000);
            Appartment app2 = new Appartment("Appartementstraat 15", 3, 320000);

            House house1 = new House("Huisstraat 10", 1, 220000);
            House house2 = new House("Huisstraat 31", 3, 380000);

            immo.AddAppartment(app1);
            immo.AddAppartment(app2);

            immo.AddHouse(house1);
            immo.AddHouse(house2);

            Console.WriteLine("All appartments for sale:");
            immo.ShowAllAppartments();

            Console.WriteLine("----------------");

            Console.WriteLine("All houses for sale:");
            immo.ShowAllHouses();

            Console.ReadLine();
        }
Beispiel #2
0
        public Top10Agents CalculateTop10Agents(IReadOnlyCollection <RealEstate> objects)
        {
            var agentsDictionary = new Dictionary <int, RealEstateAgent>();

            foreach (var obj in objects)
            {
                var savedAgent = agentsDictionary.GetValueOrDefault(obj.RealEstateAgentId);
                if (savedAgent != null)
                {
                    agentsDictionary[obj.RealEstateAgentId].NumberOfObjects++;
                    continue;
                }
                var agent = new RealEstateAgent(obj.RealEstateAgentId, obj.RealEstateAgentName)
                {
                    NumberOfObjects = 1
                };
                agentsDictionary[obj.RealEstateAgentId] = agent;
            }

            var top10Agents = agentsDictionary.Values
                              .OrderByDescending(agent => agent.NumberOfObjects)
                              .Take(10)
                              .Select(agent => agent);

            return(new Top10Agents(top10Agents.ToArray()));
        }
        public async Task <IHttpActionResult> GetLeads()
        {
            DataTransfer curUser = await GetCurrentUserInfo();

            try
            {
                if (curUser.roles[0].ToLower() == "user")
                {
                    User user = userCrud.Table.First(u => u.Email == curUser.userName);
                    IQueryable <Lead> leads = leadCrud.Table.Where(l => l.UserId == user.UserId);
                    return(Ok(leads));
                }
                else if (curUser.roles[0].ToLower() == "agent")
                {
                    RealEstateAgent   agent = agentCrud.Table.First(a => a.Email == curUser.userName);
                    IQueryable <Lead> leads = leadCrud.Table.Where(l => l.RealEstateAgent == null);

                    return(Ok(leads));
                }

                else
                {
                    return(BadRequest());
                }
            } catch
            {
                return(InternalServerError());
            }
        }
        public IHttpActionResult PutRealEstateAgent(int id, RealEstateAgent realEstateAgent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != realEstateAgent.RealEstateAgentId)
            {
                return(BadRequest());
            }

            agentCrud.Update(realEstateAgent);

            try
            {
                agentCrud.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RealEstateAgentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #5
0
        public IObservable <Property> GetProperties(OfferType offerType, Filter filter)
        {
            return(Observable.Create <Property>(async observer =>
            {
                int pageCount = _settings.MaxPageCountToRetrieve;

                for (int page = 1; page <= pageCount; page++)
                {
                    _logger.LogInformation("Getting page {0}, page size {1}", page, _settings.BatchSize);

                    var pageResults = await _fundaApiClient.GetOffers(page, _settings.BatchSize, offerType, filter);
                    int totalPages = pageResults.Paging.AantalPaginas;

                    _logger.LogInformation("Received page {0}, total pages {1}", page, totalPages);
                    _logger.LogInformation("Received {0} properties", pageResults.Objects.Length);

                    foreach (Object realEstateObject in pageResults.Objects)
                    {
                        var realEstateAgent = new RealEstateAgent(realEstateObject.MakelaarId, realEstateObject.MakelaarNaam);
                        var property = new Property(realEstateObject.Adres, realEstateAgent);

                        observer.OnNext(property);
                    }

                    pageCount = Math.Min(totalPages, _settings.MaxPageCountToRetrieve);
                }
            }));
        }
        public async Task <IHttpActionResult> CheckoutLead(int id, Lead lead)
        {
            // get cur user info
            DataTransfer curUser = await GetCurrentUserInfo();

            User user = new User();

            if (curUser.roles[0].ToLower() == "user")
            {
                user = userCrud.Table.First(u => u.Email == curUser.userName);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (curUser.roles[0].ToLower() == "user")
            {
                if (id != lead.LeadId)
                {
                    return(BadRequest("Editing the wrong lead"));
                }



                if (user.UserId != lead.UserId)
                {
                    return(BadRequest("User did not create lead"));
                }
            }

            RealEstateAgent agentFavoriting = agentCrud.Table.ToList().Find(agent => agent.Email == curUser.userName);

            lead.RealEstateAgentId = agentFavoriting.RealEstateAgentId;

            leadCrud.Update(lead);
            agentCrud.Update(agentFavoriting);

            try
            {
                //leadCrud.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeadExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #7
0
        public void GetRealEstateAgentTest()
        {
            RealEstateAgentsControllerInitializer();
            int             id           = 2;
            RealEstateAgent currentAgent = agentCrud.GetByID(id);
            string          expected     = "Hugo";
            string          actual       = currentAgent.FirstName;

            Assert.AreEqual(expected, actual);
        }
 public HttpResponseMessage EmailCheck(RealEstateAgent agent)
 {
     if (RealEstateAgentEmailExists(agent.Email))
     {
         int HttpResponse = 400;
         var response     = Request.CreateResponse((HttpStatusCode)HttpResponse);
         response.ReasonPhrase = "Duplicate email";
         return(response);
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
        public IHttpActionResult GetRealEstateAgent(int id)
        {
            RealEstateAgent realEstateAgent = agentCrud.GetByID(id);

            if (realEstateAgent == null)
            {
                return(NotFound());
            }

            return(Ok(realEstateAgent));
        }
        public IHttpActionResult PostRealEstateAgent(RealEstateAgent realEstateAgent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            agentCrud.Insert(realEstateAgent);

            return(CreatedAtRoute("DefaultApi", new { id = realEstateAgent.RealEstateAgentId }, realEstateAgent));
        }
Beispiel #11
0
        public void PutRealEstateAgentTest()
        {
            RealEstateAgentsControllerInitializer();
            int             id        = 5;
            Random          rnd       = new Random();
            RealEstateAgent currAgent = agentCrud.GetByID(id);

            currAgent.Password = rnd.Next(10000, 99999).ToString();
            agentCrud.Update(currAgent);
            string expected = currAgent.Password;
            string actual   = agentCrud.GetByID(id).Password;

            Assert.AreEqual(expected, actual);
        }
        public async Task <IHttpActionResult> CheckInLead(int id, Lead lead)
        {
            // get cur user info
            DataTransfer curUser = await GetCurrentUserInfo();


            if (curUser.roles[0].ToLower() == "user")
            {
                return(BadRequest("Users cannot unfavorite leads"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            RealEstateAgent agentUnFavoriting = agentCrud.Table.ToList().Find(agent => agent.Email == curUser.userName);

            if (agentUnFavoriting.RealEstateAgentId != lead.RealEstateAgentId)
            {
                return(BadRequest("Agent did not favorite this lead"));
            }

            lead.RealEstateAgent   = null;
            lead.RealEstateAgentId = null;

            leadCrud.Update(lead);
            agentCrud.Update(agentUnFavoriting);

            try
            {
                //leadCrud.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeadExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #13
0
        public async Task <ActionResult> Delete(int id, RealEstateAgent agent)
        {
            HttpRequestMessage apiRequest = CreateRequestToService(HttpMethod.Delete, $"api/RealEstateAgents/{id}");

            // add user object with JSON formater to request content
            apiRequest.Content = new ObjectContent <RealEstateAgent>(agent, new JsonMediaTypeFormatter());

            // obtain respose from API
            HttpResponseMessage response = await httpClient.SendAsync(apiRequest);

            PassCookiesToClient(response);

            if (!response.IsSuccessStatusCode)
            {
                TempData["error"] = response.ReasonPhrase;
                return(View("Error"));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #14
0
        public void PostRealEstateAgentTest()
        {
            RealEstateAgentsControllerInitializer();
            int             agentIndex = agentCrud.Table.Count();
            RealEstateAgent newAgent   = new RealEstateAgent
            {
                FirstName = "Allison",
                LastName  = "Ross",
                Email     = "*****@*****.**",
                Password  = "******",
                Alias     = "TestDb"
            };

            agentCrud.Insert(newAgent);
            int actual   = agentCrud.Table.Count();
            int expected = agentIndex + 1;

            Assert.AreEqual(expected, actual);
        }
Beispiel #15
0
        public async Task<ActionResult> Favorite(int id, Lead leadToFav)
        {
            //var httpClient = new HttpClient();

            //httpClient = new HttpClient(new HttpClientHandler() { UseCookies = false })
            //{
            //    Timeout = TimeSpan.FromMinutes(5)
            //};

            HttpRequestMessage leadRequest = CreateRequestToService(HttpMethod.Get, "api/Leads/" + id);
            HttpResponseMessage leadResponse = await httpClient.SendAsync(leadRequest);
            if (!leadResponse.IsSuccessStatusCode)
            {
                return View("Error");
            }
            leadToFav = leadResponse.Content.ReadAsAsync<Lead>().Result;

            //get current real estate agent account
            HttpRequestMessage userRequest = CreateRequestToService(HttpMethod.Get, "api/Users/currentuser");
            HttpResponseMessage userResponse = await httpClient.SendAsync(userRequest);
            var curUser = userResponse.Content.ReadAsAsync<DataTransfer>().Result;

            //get list of agents
            HttpRequestMessage agentsRequest = CreateRequestToService(HttpMethod.Get, "api/RealEstateAgents");
            HttpResponseMessage agentsResponse = await httpClient.SendAsync(agentsRequest);
            var agents = await agentsResponse.Content.ReadAsAsync<IEnumerable<RealEstateAgent>>();

            int agentid = agents.Where(a => a.Email == curUser.userName).First().RealEstateAgentId;
            RealEstateAgent currentAgent = agents.Where(agent => agent.RealEstateAgentId == agentid).First();
            //leadToFav.RealEstateAgent = currentAgent;
            leadToFav.RealEstateAgentId = currentAgent.RealEstateAgentId;

            HttpRequestMessage favRequest = CreateRequestToService(HttpMethod.Put, "api/Leads/checkout/" + id);
            favRequest.Content = new ObjectContent<Lead>(leadToFav, new JsonMediaTypeFormatter());
            HttpResponseMessage favResponse = await httpClient.SendAsync(favRequest);
            
            if (!favResponse.IsSuccessStatusCode)
            {
                return View("Error");
            }

            return RedirectToAction("Index");
        }
Beispiel #16
0
        public async Task <ActionResult> EditRealEstateAgent()
        {
            // create request
            RealEstateAgent    agent   = TempData["agent"] as RealEstateAgent;
            HttpRequestMessage request = CreateRequestToService(HttpMethod.Put, $"api/RealEstateAgents/{agent.RealEstateAgentId}");

            request.Content = new ObjectContent <RealEstateAgent>(agent, new JsonMediaTypeFormatter());

            // obtain respose from API
            HttpResponseMessage response = await httpClient.SendAsync(request);

            PassCookiesToClient(response);

            if (!response.IsSuccessStatusCode)
            {
                TempData["error"] = response.ReasonPhrase;
                return(View("Error"));
            }
            //return RedirectToAction("Index");
            return(RedirectToAction("Index", "Lead"));
        }
Beispiel #17
0
        public async Task <ActionResult> Create(RealEstateAgent realEstateAgent)
        {
            HttpRequestMessage apiEmailRequest = CreateRequestToService(HttpMethod.Post, $"api/RealEstateAgents/emailcheck");

            apiEmailRequest.Content = new ObjectContent <RealEstateAgent>(realEstateAgent, new JsonMediaTypeFormatter());
            HttpResponseMessage emailResponse = await httpClient.SendAsync(apiEmailRequest);

            PassCookiesToClient(emailResponse);

            if (!emailResponse.IsSuccessStatusCode)
            {
                ViewBag.message = emailResponse.ReasonPhrase;
                return(View("Create"));
            }


            HttpRequestMessage apiRequest = CreateRequestToService(HttpMethod.Post, $"api/RealEstateAgents");

            apiRequest.Content = new ObjectContent <RealEstateAgent>(realEstateAgent, new JsonMediaTypeFormatter());
            HttpResponseMessage response = await httpClient.SendAsync(apiRequest);

            PassCookiesToClient(response);

            if (!response.IsSuccessStatusCode)
            {
                TempData["error"] = response.ReasonPhrase;
                return(View("Error"));
            }

            Account account = new Account()
            {
                Email    = realEstateAgent.Email,
                Password = realEstateAgent.Password
            };

            TempData["role"]    = "agent";
            TempData["account"] = account;

            return(RedirectToAction("Register", "Account"));
        }
Beispiel #18
0
        public async Task <ActionResult> EditAccount(int id, RealEstateAgent realEstateAgentToEdit)
        {
            TempData["agent"] = realEstateAgentToEdit;

            HttpRequestMessage  apiRequest = CreateRequestToService(HttpMethod.Get, $"api/RealEstateAgents/{id}");
            HttpResponseMessage response   = await httpClient.SendAsync(apiRequest);

            PassCookiesToClient(response);
            var oldRealEstateAgent = response.Content.ReadAsAsync <RealEstateAgent>().Result;

            if (!response.IsSuccessStatusCode)
            {
                TempData["error"] = response.ReasonPhrase;
                return(View("Error"));
            }
            Account account = new Account()
            {
                Email    = realEstateAgentToEdit.Email,
                Password = realEstateAgentToEdit.Password
            };
            HttpRequestMessage accountRequest = CreateRequestToService(HttpMethod.Post, $"api/Accounts/Edit/{oldRealEstateAgent.Email}");

            accountRequest.Content = new ObjectContent <Account>(account, new JsonMediaTypeFormatter());
            // obtain respose from API
            HttpResponseMessage newAccountResponse = await httpClient.SendAsync(accountRequest);

            PassCookiesToClient(newAccountResponse);

            if (!newAccountResponse.IsSuccessStatusCode)
            {
                TempData["error"] = newAccountResponse.ReasonPhrase;
                return(View("Error"));
            }

            //return RedirectToAction("Index"); old behavior
            return(RedirectToAction("EditRealEstateAgent"));
        }
Beispiel #19
0
 protected bool Equals(RealEstateAgent other)
 {
     return(Id == other.Id);
 }