Exemplo n.º 1
0
        internal async Task <HomeStatus> GetHomeStatus(string homeId)
        {
            if (!await CheckConnectionAsync().ConfigureAwait(false))
            {
                return(null);
            }
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters["home_id"]      = homeId;
            parameters["device_types"] = ""; // array of device types

            using (HttpClient client = new HttpClient())
                using (HttpRequestMessage request = new HttpRequestMessage())
                {
                    request.Method     = HttpMethod.Post;
                    request.RequestUri = new Uri(host + apiPath + "/homestatus");

                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
                    request.Content = new StringContent(parameters.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");
                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    HomeStatus homeStatus = new HomeStatus().FromJson(responseBody);
                    if (homeStatus.Status != "ok")
                    {
                        ErrorMessageData errorMessageData = new ErrorMessageData().FromJson(responseBody);
                        _errorMessage = errorMessageData.Error.Message;
                        return(null);
                    }
                    return(homeStatus);
                }
        }
Exemplo n.º 2
0
        private async Task <PropertyCountServiceModel> GetByCategoryAsync(HomeStatus managed, HomeCategory category)
        {
            var exampleImage = string.Empty;

            var count = await this.context.Homes
                        .Where(h => h.Status != managed && h.Category == category)
                        .CountAsync();

            if (category == HomeCategory.Apartment)
            {
                exampleImage = ApartmentImage;
            }
            else if (category == HomeCategory.House)
            {
                exampleImage = HouseImage;
            }
            else if (category == HomeCategory.Room)
            {
                exampleImage = RoomImage;
            }

            var categoryUpper = category.ToString().FirstCharToUpper();

            var model = new PropertyCountServiceModel
            {
                CategoryName = category.ToString().FirstCharToUpper() + "s",
                Count        = count,
                ExampleImage = exampleImage,
            };

            return(model);
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            HomeStatus homestatus = db.Status.Find(id);

            db.Status.Remove(homestatus);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        [Fact] // async Task<bool> EditListingAsync(OwnerEditListingServiceModel model)
        public async Task EditHomeStatusAsync_WithGivenRequestObject_ShouldChangeStatusAndReturnString()
        {
            // Arrange
            string       newName        = "New house on the block";
            string       newDescription = "Well maintained house close to the beach";
            HomeStatus   newStatus      = HomeStatus.Rented;
            HomeCategory newCategory    = HomeCategory.Room;

            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);
            var image   = ImageCreator.CreateForModel();
            var home    = HomeCreator.CreateAny(city.Id);

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddAsync(home);

            await this.Context.CloudImages.AddAsync(image);

            await this.Context.SaveChangesAsync();

            var model = new OwnerEditListingServiceModel
            {
                Id          = home.Id,
                Name        = newName,
                Description = newDescription,
                Price       = 1000m,
                Status      = newStatus,
                Category    = newCategory,
                Image       = image,
            };

            var service = new OwnerListingService(this.Context, null, null, null);

            // Act
            var savedEntry = await this.Context.Homes.Where(h => h.Id == home.Id).FirstOrDefaultAsync();

            var result = await service.EditListingAsync(model);

            var expected = true;

            // Assert
            result.Should().Be(true);
            result.Should().Equals(expected);

            savedEntry.Should().NotBeNull();
            savedEntry.Id.Should().Be(model.Id);
            savedEntry.Name.Should().Match(model.Name);
            savedEntry.Description.Should().Match(model.Description);
            savedEntry.Price.Should().Be(model.Price);
            savedEntry.Status.Should().Be(model.Status);
            savedEntry.Category.Should().Be(model.Category);
            savedEntry.Images.Select(i => i.PictureUrl).FirstOrDefault()
            .Should()
            .Match(model.Image.PictureUrl);
        }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "HomeStatusId,StatusName,ProfileId")] HomeStatus homestatus)
 {
     if (ModelState.IsValid)
     {
         db.Entry(homestatus).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(homestatus));
 }
Exemplo n.º 6
0
        public ActionResult PostStaus(string name)
        {
            HomeStatus aStatus = new HomeStatus();

            aStatus.StatusName = name;
            // aCategory.Code = code;
            db.Status.Add(aStatus);
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        public ActionResult PostStatus(string name, string status)
        {
            HomeStatus aStatus = new HomeStatus();

            aStatus.FullName   = name;
            aStatus.StatusName = status;
            db.Status.Add(aStatus);
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "HomeStatusId,StatusName,ProfileId")] HomeStatus homestatus)
        {
            if (ModelState.IsValid)
            {
                db.Status.Add(homestatus);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(homestatus));
        }
Exemplo n.º 9
0
        // GET: /Status/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HomeStatus homestatus = db.Status.Find(id);

            if (homestatus == null)
            {
                return(HttpNotFound());
            }
            return(View(homestatus));
        }
Exemplo n.º 10
0
        public IHttpActionResult Get(int Id)
        {
            try
            {
                Home home = new HomeDAL().Get(Id);

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

                IList <HomeStatus> homeStatus     = new HomeStatusDAL().List();
                HomeStatus         nextHomeStatus = null;

                int index = -1;

                for (int i = 0; i < homeStatus.Count; i++)
                {
                    if (homeStatus[i].Id == home.HomeStatusId)
                    {
                        index = ++i;
                        break;
                    }
                }

                if (index >= 0 && index < homeStatus.Count)
                {
                    nextHomeStatus = homeStatus[index];
                }

                return(Ok(new { Home = home, HomeStatus = homeStatus, nextHomeStatus }));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 11
0
        private async Task <IEnumerable <PropertyListServiceModel> > GetByStatusAsync(HomeStatus status)
        {
            var model = await this.context.Homes
                        .Include(x => x.City)
                        .Include(x => x.City.Country)
                        .Include(h => h.Images)
                        .Where(h => h.Status == status)
                        .Select(x => new PropertyListServiceModel
            {
                Id       = x.Id,
                Name     = x.Name,
                City     = x.City.Name,
                Country  = x.City.Country.Name,
                Price    = x.Price,
                Status   = x.Status,
                Category = x.Category,
                Image    = x.Images.Select(i => i.PictureUrl).FirstOrDefault(),
            })
                        .ToListAsync();

            return(model);
        }