public static ApartmentEntity ToEntity(this Apartment apartment, string partitionKey, Guid rowKey)
        {
            var entity = new ApartmentEntity();

            entity.UniqueId         = entity.UniqueId == Guid.Empty ? rowKey : apartment.UniqueId;
            entity.Address          = apartment.Address;
            entity.Created          = apartment.Created;
            entity.Updated          = apartment.Updated;
            entity.IsCreatedByOwner = apartment.IsCreatedByOwner;
            entity.Price            = apartment.Price.ToString(CultureInfo.InvariantCulture);
            entity.Rooms            = apartment.Rooms;
            entity.Uri = apartment.Uri.AbsoluteUri;

            var sb = new StringBuilder();

            foreach (string phone in apartment.Phones)
            {
                sb.Append(phone);
                sb.Append(';');
            }

            entity.Phones       = sb.ToString();
            entity.PartitionKey = partitionKey;
            entity.RowKey       = rowKey.ToString();

            return(entity);
        }
示例#2
0
 public static ApartmentInfo ToCore(this ApartmentEntity data)
 {
     if (data == null)
     {
         return(null);
     }
     return(new ApartmentInfo
     {
         ExternalId = data.ExternalId,
         Location = new PointLatLng(data.Lat, data.Lng),
         Price = data.Price,
         Url = data.Url,
         ApartmentNumber = data.ApartmentNumber,
         Floor = data.Floor,
         FloorsCount = data.FloorsCount,
         RoomsCount = data.RoomsCount,
         Area = data.Area,
         Title = data.Title,
         Address = data.Address,
         PublishingDateUtc = data.PublishingDate,
         DisappearedDate = data.DisappearedDate,
         CreatedAtUtc = data.CreatedAtUtc,
         ImageUrls = JsonConvert.DeserializeObject <ICollection <string> >(data.ImageUrlsJson)
     });
 }
示例#3
0
        public string UpdateLocation(string type,
                                     string lattitude,
                                     string longitude,
                                     string address,
                                     string name,
                                     int price,
                                     double distanceToClosestConnector,
                                     double distanceToClosestGym)
        {
            if (type == null || lattitude == null || longitude == null)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return("type, lattitude and longitude cannot be null");
            }
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(STORAGE_CONFIGURATION_KEY);
            CloudTableClient    tableClient    = storageAccount.CreateCloudTableClient();
            CloudTable          table          = tableClient.GetTableReference(TABLE_NAME);

            // Create a location entity.
            LocationEntity loc;

            if (type == "apartment")
            {
                loc = new ApartmentEntity(address, lattitude, longitude, name, price, distanceToClosestConnector, distanceToClosestGym);
            }
            else
            {
                loc = new LocationEntity(type, address, lattitude, longitude, name);
            }
            table.Execute(TableOperation.InsertOrReplace(loc));
            return(null);
        }
示例#4
0
        protected ApartmentModel ApartmentEntityToModel(ApartmentEntity entity)
        {
            var imagesIdList    = JsonConvert.DeserializeObject <List <int> >(entity.ImageIds);
            var imageModelsList = new List <ImageModel>();

            foreach (int imageId in imagesIdList)
            {
                imageModelsList.Add(
                    new ImageModel
                {
                    FileLocation = _dbContext.Images.First(img => img.Id == imageId).FileLocation
                }
                    );
            }

            return(new ApartmentModel
            {
                Id = entity.Id,
                Name = entity.Name,
                Description = entity.Description,
                LocationName = entity.LocationName,
                Sleeps = entity.Sleeps,
                Images = imageModelsList
            });
        }
        public static Apartment ToApartment(this ApartmentEntity entity)
        {
            var apartment = new Apartment
            {
                UniqueId         = entity.UniqueId == Guid.Empty ? Guid.Parse(entity.RowKey) : entity.UniqueId,
                Address          = entity.Address,
                Created          = entity.Created ?? DateTime.MinValue,
                Updated          = entity.Updated ?? DateTime.MinValue,
                IsCreatedByOwner = entity.IsCreatedByOwner,
                Price            = float.Parse(entity.Price),
                Rooms            = entity.Rooms,
                Uri    = new Uri(entity.Uri),
                Phones = entity.Phones.Split(';')
                         .Where(x => !String.IsNullOrEmpty(x.Trim())).ToList()
            };

            return(apartment);
        }
        public ApartmentApiResponseModel CreateAndRedirectToEdit(ApartmentSaveModel addedApartment)
        {
            var apartmentEntity = new ApartmentEntity
            {
                Name         = addedApartment.Name,
                LocationName = addedApartment.LocationName,
                Description  = addedApartment.Description,
                Sleeps       = addedApartment.Sleeps,
                ImageIds     = JsonConvert.SerializeObject(addedApartment.ImageIds)
            };

            _dbContext.Apartments.Add(apartmentEntity);
            _dbContext.SaveChanges();

            return(new ApartmentApiResponseModel
            {
                RedirectUrl = $"/Admin/ApartmentSingle/Edit/{apartmentEntity.Id}"
            });
        }
示例#7
0
        protected ApartmentSaveModel ApartmentEntityToSaveModel(ApartmentEntity entity)
        {
            var    imagesIdList  = JsonConvert.DeserializeObject <List <int> >(entity.ImageIds);
            string mainImagePath = null;

            if (imagesIdList.Count > 0 && imagesIdList != null)
            {
                mainImagePath = _dbContext.Images.First(img => img.Id == imagesIdList[0]).FileLocation;
            }

            return(new ApartmentSaveModel
            {
                Id = entity.Id,
                Name = entity.Name,
                Description = entity.Description,
                LocationName = entity.LocationName,
                Sleeps = entity.Sleeps,
                ImageIds = imagesIdList,
                MainImagePath = mainImagePath
            });
        }