Ejemplo n.º 1
0
 public Address PostSave(Address address)
 {
     if (address.Id > 0)
     {
         //DatabaseContext.Database.Update(address);.
         _addressRepo.Update(address.Id, address);
         return(address);
     }
     else
     {
         return(_addressRepo.Insert(address));
         //  DatabaseContext.Database.Save(address);
     }
 }
Ejemplo n.º 2
0
        private List <Apartment> MapData(DataTable table, int id = -1)
        {
            var list = new List <Apartment>(table.Rows.Count - 1);

            foreach (DataRow row in table.AsEnumerable())
            {
                var values      = row.ItemArray;
                var existingApt = _apartmentRepo
                                  .GetAll()
                                  .FirstOrDefault(a => a.Name.Equals(values[0].ToString(), StringComparison.OrdinalIgnoreCase) && a.BuildingId == id);

                if (existingApt != null)
                {
                    existingApt.Name     = values[0].ToString();
                    existingApt.StatusId = GetStatus(values[1].ToString()) != null?GetStatus(values[1].ToString()).Id : -1;

                    existingApt.Size          = values[2].ToString();
                    existingApt.NumberOfRooms = int.Parse(values[3].ToString());
                    existingApt.Price         = decimal.Parse(values[4].ToString());
                    existingApt.BuildingId    = id;
                    var isUpdatedApt = _apartmentRepo.Update(existingApt.Id, existingApt);
                    if (isUpdatedApt)
                    {
                        list.Add(existingApt);
                    }
                    continue;
                }
                else
                {
                    var apartment = new Apartment();
                    apartment.Name     = values[0].ToString();
                    apartment.StatusId = GetStatus(values[1].ToString()) != null?GetStatus(values[1].ToString()).Id : -1;

                    apartment.Size          = values[2].ToString();
                    apartment.NumberOfRooms = int.Parse(values[3].ToString());
                    apartment.Price         = decimal.Parse(values[4].ToString());
                    apartment.BuildingId    = id;
                    var newApartment = _apartmentRepo.Insert(apartment);
                    if (newApartment != null)
                    {
                        list.Add(newApartment);
                    }
                    continue;
                }
            }
            return(list);
        }
Ejemplo n.º 3
0
        public BuildingBackOfficeModel PostSave(BuildingBackOfficeModel model)
        {
            var building  = model.Building;
            var addresses = model.Addresses;

            umbraco.BusinessLogic.User siteAdmin = umbraco.helper.GetCurrentUmbracoUser();

            if (building.Id > 0)
            {
                building.ModifiedBy = siteAdmin.Id;
                building.ModifiedOn = DateTime.Now;
                _bldgRepo.Update(building.Id, building);
            }
            else
            {
                building.CreatedBy  = siteAdmin.Id;
                building.CreatedOn  = DateTime.Now;
                building.ModifiedBy = siteAdmin.Id; //should be nullable BM-21 fix
                building.ModifiedOn = DateTime.Now; //should be nullable BM-21 fix
                var buildingInserted = _bldgRepo.Insert(building);
                building.Id = buildingInserted.Id;
            }

            foreach (var address in addresses)
            {
                if (address.Id > 0)
                {
                    //DatabaseContext.Database.Update(address);
                    _addressRepo.Update(address.Id, address);
                }
                else
                {
                    if (!IsCanceledAddress(address))
                    {
                        address.BuildingId = building.Id;
                        //DatabaseContext.Database.Save(address);
                        _addressRepo.Insert(address);
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 4
0
        public Building CreateBuilding(Building building, string documentType, int parentId = 0)
        {
            //TODO: this way to find the 'main' parent sucks, should find a better way
            //through umbraco application published context
            var accountPropValue = Context.PublishedContentRequest.PublishedContent
                                   .Parent
                                   .Parent
                                   .GetValidPropertyValue(Constants.ACCOUNT_PROPERTY_ALIAS).ToString();

            int accountId = -1;

            int.TryParse(accountPropValue, out accountId);

            if (accountId <= 0)
            {
                return(null);
            }

            //if account prop value was found
            var memberId = _memberHelper.GetCurrentMember().Id;

            Building newBuilding = new Building();

            newBuilding.AccountId   = accountId;
            newBuilding.CreatedBy   = memberId;
            newBuilding.ModifiedBy  = memberId;
            newBuilding.CreatedOn   = DateTime.Now;
            newBuilding.ModifiedOn  = DateTime.Now;
            newBuilding.Description = building.Description;
            newBuilding.Name        = building.Name;


            var buildingInserted = _buildingRepo.Insert(newBuilding);

            //Try Create Building Content on backoffice
            if (buildingInserted != null)
            {
                IContent buildingContent = CreateBuildingContent(buildingInserted, documentType, parentId);
            }

            return(buildingInserted);
        }
Ejemplo n.º 5
0
        public void UpdateAsset(int buildingId, int mediaId)
        {
            //check if child media node already exists in the db
            var dbassetExisting = _buildingAssetRepo.GetById(mediaId);

            if (dbassetExisting != null)
            {
                dbassetExisting.BuildingId = buildingId;
                dbassetExisting.MediaId    = mediaId;
                dbassetExisting.TypeId     = (int)AssetMediaType.Image;

                //just update to make sure it's referenced to correct buildign and media
                _buildingAssetRepo.Update(dbassetExisting.Id, dbassetExisting);
            }
            else
            {
                //re-add each media to db asset table
                _buildingAssetRepo.Insert((BuildingAsset)AssetFactory.CreateAsset(AssetType.Building, buildingId, mediaId, AssetMediaType.Image));
            }
        }
Ejemplo n.º 6
0
 private ApartmentFolder SaveApartmentFolder(int apartmentId, string name)
 {
     return(_apartmentFolderRepo.Insert(new ApartmentFolder {
         ApartmentId = apartmentId, Name = name
     }));
 }
Ejemplo n.º 7
0
 private BuildingFolder SaveBuildingFolder(int accountId, int buildingId, string name)
 {
     return(_buildingFolderRepo.Insert(new BuildingFolder {
         AccountId = accountId, Name = name, BuildingId = buildingId
     }));
 }
Ejemplo n.º 8
0
 private AccountFolder SaveAccountFolder(int accountId, string name)
 {
     return(_accountFolderRepo.Insert(new AccountFolder {
         AccountId = accountId, Name = name
     }));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Method to upload the media/asset files for a building or apartment
        /// Building assets are images
        /// Apartment assets are files (excel,csv,pdf, etc)
        /// </summary>
        /// <param name="files"></param>
        /// <param name="buildingId"></param>
        /// <param name="parentId"></param>
        /// <param name="apartmentId"></param>
        /// <returns></returns>
        public IList <IMedia> UploadMediaFiles(HttpFileCollectionBase files, int buildingId, int parentId, int apartmentId = -1)
        {
            IList <IMedia> media = new List <IMedia>();

            foreach (var fileKey in files)
            {
                var fileContent = files[fileKey.ToString()];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    fileContent.InputStream.Position = 0;
                    var    binaryReader = new BinaryReader(fileContent.InputStream);
                    byte[] binData      = binaryReader.ReadBytes(fileContent.ContentLength);
                    var    fileName     = Path.GetFileName(fileContent.FileName);

                    var mediaType = "File"; //default

                    //check if supported
                    var isImageSupported = IMAGEFORMATS_SUPPORTED.Any(x => fileContent.FileName.EndsWith(x, System.StringComparison.OrdinalIgnoreCase));
                    var isFileSupported  = FILEFORMATS_SUPPORTED.Any(x => fileContent.FileName.EndsWith(x, System.StringComparison.OrdinalIgnoreCase));

                    if (isImageSupported)
                    {
                        mediaType = "Image";
                    }

                    if (isFileSupported)
                    {
                        mediaType = "File";
                    }

                    if (!isImageSupported && !isFileSupported)
                    {
                        continue;
                    }

                    if (binData != null && binData.Length > 0)
                    {
                        var propertyTypeAlias = "umbracoFile";
                        var newMedia          = _mediaService.CreateMedia(fileName, parentId, mediaType);
                        if (newMedia != null)
                        {
                            newMedia.SetValue(propertyTypeAlias, fileContent);
                            _mediaService.Save(newMedia);

                            //add to repository to building asset by default
                            if (apartmentId <= 0)
                            {
                                _buildingAssetRepo.Insert((BuildingAsset)AssetFactory.CreateAsset(AssetType.Building, buildingId, newMedia.Id, AssetMediaType.Image));
                            }
                            else
                            {
                                _apartmentAssetRepo.Insert((ApartmentAsset)AssetFactory.CreateAsset(AssetType.Apartment, apartmentId, newMedia.Id, AssetMediaType.File));
                            }

                            //add newly added media to list
                            media.Add(newMedia);
                        }
                    }
                }
            }
            return(media);
        }