Example #1
0
        /// <summary>
        /// Domain behaviours - methods/operations
        /// </summary>

        #region Domain behaviours - methods/operations

        public Property Update(  // Note, rental status is NOT updated manually, but based on other services
            Property property,
            string propertyName,
            string propertyDesc,
            PropertyType propertyType,
            int propertyBuildYear,
            bool isActive,
            bool isShared,
            RentalStatus rentalStatus,
            bool isBasementSuite,
            DateTime updateDate,
            PropertyAddress propertyAddress,
            PropertyFacility propertyFacility,
            PropertyFeature propertyFeature
            )
        {
            property.PropertyName      = propertyName;
            property.PropertyDesc      = propertyDesc;
            property.Type              = propertyType;
            property.PropertyBuildYear = propertyBuildYear;
            property.IsActive          = isActive;
            property.IsShared          = isShared;
            property.IsBasementSuite   = isBasementSuite;
            property.Modified          = updateDate;
            property.Address           = propertyAddress;
            property.Facility          = propertyFacility;
            property.Feature           = propertyFeature;

            return(property);
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            PropertyFacility propertyFacility = db.PropertyFacility.Find(id);

            db.PropertyFacility.Remove(propertyFacility);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
        /// <summary>
        /// Constructor - for creating new instance with all required parameters (enforced)
        /// </summary>
        ///
        public CreatePropertyCommand(
            //int propertyId,
            string propertyName,
            string propertyDesc,
            PropertyType propertyType,
            //int? strataCouncilId,
            //int propertyAddressId,
            //int propertyFeatureId,
            //int propertyFacilityId,
            //int? propertyOwnerId,
            //int? propertyManagerId,
            //string propertyLogoImgUrl,
            //string propertyVideoUrl,
            int propertyBuildYear,
            //int propertyMgmntlStatusId,
            bool isActive,
            bool isShared,
            //int? furnishingId,
            RentalStatus rentalStatus,
            bool isBasementSuite,
            DateTime createdDate,
            DateTime updateDate,
            PropertyAddress propertyAddress,
            PropertyFacility propertyFacility,
            PropertyFeature propertyFeature//,

            //int propertyTypeId, //PropertyType propertyType,
            //int rentalStatusId
            )
        {
            //PropertyId = propertyId;
            PropertyName = propertyName;
            PropertyDesc = propertyDesc;
            Type         = propertyType;
            //StrataCouncilId = strataCouncilId;
            //PropertyAddressId = propertyAddressId;
            //PropertyFeatureId = propertyFeatureId;
            //PropertyFacilityId = propertyFacilityId;
            //PropertyOwnerId = propertyOwnerId;
            //PropertyManagerId = propertyManagerId;
            //PropertyLogoImgUrl = propertyLogoImgUrl;
            //PropertyVideoUrl = propertyVideoUrl;
            PropertyBuildYear = propertyBuildYear;
            //PropertyMgmntlStatusId = propertyMgmntlStatusId;
            IsActive = isActive;
            IsShared = isShared;
            //FurnishingId = furnishingId;
            Status           = rentalStatus;
            IsBasementSuite  = isBasementSuite;
            CreatedDate      = createdDate;
            UpdateDate       = updateDate;
            PropertyAddress  = propertyAddress;
            PropertyFacility = propertyFacility;
            PropertyFeature  = propertyFeature;

            //PropertyTypeId = propertyTypeId; //PropertyType = propertyType;
            //RentalStatusId = rentalStatusId;//RentalStatus = rentalStatus;
        }
Example #4
0
 public ActionResult Edit([Bind(Include = "Id,FacilitiesName")] PropertyFacility propertyFacility)
 {
     if (ModelState.IsValid)
     {
         db.Entry(propertyFacility).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(propertyFacility));
 }
Example #5
0
        public PropertyFacilityViewModel(PropertyFacility entity, Action <PropertyFacilityViewModel> act = null)
        {
            if (entity == null)
            {
                return;
            }

            Entity = entity;
            act?.Invoke(this);
        }
Example #6
0
        public ActionResult Create([Bind(Include = "Id,FacilitiesName")] PropertyFacility propertyFacility)
        {
            if (ModelState.IsValid)
            {
                db.PropertyFacility.Add(propertyFacility);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(propertyFacility));
        }
Example #7
0
        // GET: PropertyFacilities/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PropertyFacility propertyFacility = db.PropertyFacility.Find(id);

            if (propertyFacility == null)
            {
                return(HttpNotFound());
            }
            return(View(propertyFacility));
        }
Example #8
0
        /// <summary>
        /// Constructor - for creating new instance with all required parameters (enforced)
        /// </summary>
        ///
        public Property(
            string propertyName,
            string propertyDesc,
            PropertyType propertyType,
            string propertyManagerUserName,
            int propertyBuildYear,
            bool isActive,
            bool isShared,
            RentalStatus rentalStatus,
            bool isBasementSuite,
            DateTime createdDate,
            DateTime updateDate,

            //OwnerAddress ownerAddress,

            PropertyAddress propertyAddress,
            PropertyFacility propertyFacility,
            PropertyFeature propertyFeature

            )
        {
            PropertyName            = propertyName;
            PropertyDesc            = propertyDesc;
            Type                    = propertyType;
            PropertyManagerUserName = propertyManagerUserName;
            PropertyBuildYear       = propertyBuildYear;
            IsActive                = isActive;
            IsShared                = isShared;
            Status                  = rentalStatus;
            IsBasementSuite         = isBasementSuite;
            Created                 = createdDate;
            Modified                = updateDate;

            //OAddress = ownerAddress;
            Address  = propertyAddress;
            Facility = propertyFacility;
            Feature  = propertyFeature;
        }
Example #9
0
        public async Task <CreatePropertyCommandResult> Handle(CreatePropertyCommand request, CancellationToken cancellationToken)
        {
            #region Create property aggregate root

            var createdProperty = new CreatePropertyCommandResult();

            var address = new PropertyAddress(request.PropertySuiteNumber,
                                              request.PropertyNumber, request.PropertyStreet,
                                              request.PropertyCity, request.PropertyStateProvince, request.PropertyZipPostCode,
                                              request.PropertyCountry);

            var feature = new PropertyFeature(request.NumberOfBathrooms,
                                              request.NumberOfBathrooms, request.NumberOfLayers,
                                              request.NumberOfParking, request.BasementAvailable,
                                              request.TotalLivingArea, request.IsShared, request.FeatureNotes);


            var facility = new PropertyFacility(request.Stove, request.Refrigerator, request.Dishwasher,
                                                request.AirConditioner, request.Laundry, request.BlindsCurtain, request.Furniture,
                                                request.Tvinternet, request.CommonFacility, request.SecuritySystem, request.UtilityIncluded,
                                                request.FireAlarmSystem, request.FacilityNotes, request.Others);



            var property = new Property(request.PropertyName, request.PropertyDesc, request.Type, request.PropertyManagerUserName,
                                        request.PropertyBuildYear, true, request.IsShared, request.Status,
                                        request.BasementAvailable, DateTime.Now, DateTime.Now, address, facility, feature);


            await _context.AddAsync(property);

            #endregion


            PropertyOwner owner = null;

            if (request.PropertyOwnerId == 0)
            {
                object ownerAddress = null;

                if (!request.IsSameAddress)
                {
                    ownerAddress = new OwnerAddress(request.OwnerStreetNumber, request.OwnerCity, request.OwnerStateProv,
                                                    request.OwnerCountry, request.OwnerZipPostCode);
                }
                else
                {
                    ownerAddress = new OwnerAddress(request.PropertySuiteNumber + " " + request.PropertyNumber + " " + request.PropertyStreet, request.PropertyCity, request.PropertyStateProvince,
                                                    request.PropertyCountry, request.PropertyZipPostCode);
                }

                owner = property.AddOwner("NotSet", request.FirstName, request.LastName, request.ContactEmail,
                                          request.ContactTelephone1, request.ContactTelephone2, request.OnlineAccessEnbaled, request.UserAvartaImgUrl,
                                          request.IsActive, request.RoleId, request.Notes, (OwnerAddress)ownerAddress);


                await _context.AddAsync(owner);
            }
            else
            {
                owner = _context.PropertyOwner.FirstOrDefault(o => o.Id == request.PropertyOwnerId);

                var ownerProperty = property.AddExsitingOwner(owner);

                owner.OwnerProperty.Add(ownerProperty);
            }

            try
            {
                await _context.SaveChangesAsync(); // comment out for testing message sending ONLY

                int PropertyId = property.Id;

                int NewOwnerId = owner.Id;

                request.PropertyId  = property.Id;
                request.CreatedDate = property.Created;
                request.UpdateDate  = property.Modified;

                //Populate return resultEnum.GetName(typeof())
                //
                createdProperty.Id                    = PropertyId;
                createdProperty.PropertyName          = request.PropertyName;
                createdProperty.Type                  = request.Type.ToString();
                createdProperty.Status                = request.Status.ToString();
                createdProperty.PropertyLogoImgUrl    = request.PropertyLogoImgUrl;
                createdProperty.IsShared              = request.IsShared;
                createdProperty.IsActive              = request.IsActive;
                createdProperty.IsBasementSuite       = request.IsBasementSuite;
                createdProperty.CreatedDate           = DateTime.Now.ToString("MMMM dd, yyyy");
                createdProperty.UpdateDate            = DateTime.Now.ToString("MMMM dd, yyyy");
                createdProperty.PropertySuiteNumber   = request.PropertySuiteNumber;
                createdProperty.PropertyStreet        = request.PropertyStreet;
                createdProperty.PropertyCity          = request.PropertyCity;
                createdProperty.PropertyStateProvince = request.PropertyStateProvince;
                createdProperty.PropertyZipPostCode   = request.PropertyZipPostCode;
                createdProperty.PropertyCountry       = request.PropertyCountry;


                Log.Information("Property with id {PropertyName} has been successfully created.", property.PropertyName);



                // Publish Domain Event (MediatR pattern)

                AssetCore.Events.PropertyCreatedEvent domainEvent = new AssetCore.Events.PropertyCreatedEvent(property);

                await _mediator.Publish(domainEvent);



                // Publish Integration Event (RabbitMQ)

                var streetNum = request.PropertySuiteNumber + " " + request.PropertyNumber + " " + request.PropertyStreet;

                //var streetNum = address.PropertySuiteNumber + " " + address.PropertyNumber + " " + address.PropertyStreet;
                // Send message to MQ
                //
                PropertyCreatedEvent e = new PropertyCreatedEvent(Guid.NewGuid(), request.PropertyId, request.PropertyName, request.PropertyManagerUserName,
                                                                  request.PropertyBuildYear, request.Type.ToString(), request.BasementAvailable, request.IsShared, request.NumberOfBedrooms,
                                                                  request.NumberOfBathrooms, request.NumberOfLayers, request.NumberOfParking, request.TotalLivingArea,
                                                                  streetNum, request.PropertyCity, request.PropertyStateProvince, request.PropertyCountry,
                                                                  request.PropertyZipPostCode, NewOwnerId, request.FirstName, request.LastName, request.ContactEmail, request.ContactTelephone1, request.ContactTelephone2,
                                                                  request.OwnerStreetNumber, request.OwnerCity, request.OwnerStateProv, request.OwnerZipPostCode, request.OwnerCountry);

                try
                {
                    await _messagePublisher.PublishMessageAsync(e.MessageType, e, "asset_created"); // publishing the message

                    Log.Information("Message  {MessageType} with Id {MessageId} has been published successfully", e.MessageType, e.MessageId);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while publishing {MessageType} message with id {MessageId}.", e.MessageType, e.MessageId);
                }


                // Log message for reconciliation purpose         ******** This part can be replaced by Serilog ***************
                //
                var msgDetails = new MessageDetails();

                msgDetails.PrincicipalId     = e.PropertyId;
                msgDetails.PrincipalType     = "Property";
                msgDetails.PrincipalNameDesc = e.PropertyName;
                msgDetails.OperationType     = "Create";

                var details = msgDetails.ToBsonDocument();

                var msg = new Message(e.MessageId, "Asset Management", details, "asset_created", "asset_created.*", "Publish", DateTime.Now);

                await _loggingService.LogMessage(msg);
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error while creating property, {PropertyName} has not been created.", request.PropertyName);
            }

            return(createdProperty);
            //return new CreatePropertyCommandResult() { };
        }
Example #10
0
        public async Task <UpdatePropertyCommandResult> Handle(UpdatePropertyCommand request, CancellationToken cancellationToken)
        {
            var ppt = _context.Property.Include(op => op.OwnerProperty).ThenInclude(o => o.PropertyOwner).FirstOrDefault(p => p.Id == request.PropertyId);

//
            var address = new PropertyAddress(request.PropertySuiteNumber,
                                              request.PropertyNumber, request.PropertyStreet,
                                              request.PropertyCity, request.PropertyStateProvince, request.PropertyZipPostCode,
                                              request.PropertyCountry);

            var feature = new PropertyFeature(request.NumberOfBedrooms,
                                              request.NumberOfBathrooms, request.NumberOfLayers,
                                              request.NumberOfParking, request.BasementAvailable,
                                              request.TotalLivingArea, request.IsShared, request.FeatureNotes);


            var facility = new PropertyFacility(request.Stove, request.Refrigerator, request.Dishwasher,
                                                request.AirConditioner, request.Laundry, request.BlindsCurtain, request.Furniture,
                                                request.Tvinternet, request.CommonFacility, request.SecuritySystem, request.UtilityIncluded,
                                                request.FireAlarmSystem, request.Others, request.FacilityNotes);



            var updated = ppt.Update(ppt, request.PropertyName, request.PropertyDesc, request.PropertyType1, request.PropertyBuildYear,
                                     request.IsActive, request.IsShared, request.Status, request.BasementAvailable, DateTime.Now,
                                     address, facility, feature);

            _context.Property.Update(updated);

            var owners = ppt.OwnerProperty.Select(o => o.PropertyOwner).ToList();



            //var owners = _context.PropertyOwner
            //    .Include(op => op.OwnerProperty)
            //    .ThenInclude(p => p.FirstOrDefault().PropertyId == request.PropertyId).ToList();



            var contracts = _context.ManagementContract
                            //.Include(p => p.Property)
                            .Where(p => p.PropertyId == request.PropertyId).ToList();


            var updatedProperty = new UpdatePropertyCommandResult();

            // need to populate it either manual or automapper***************************
            updatedProperty.PropertyId        = request.PropertyId;
            updatedProperty.Id                = request.PropertyId;
            updatedProperty.AirConditioner    = request.AirConditioner;
            updatedProperty.BasementAvailable = request.BasementAvailable;
            updatedProperty.CommonFacility    = request.CommonFacility;
            updatedProperty.Dishwasher        = request.Dishwasher;
            updatedProperty.FacilityNotes     = request.FacilityNotes;
            updatedProperty.FireAlarmSystem   = request.FireAlarmSystem;
            //updatedProperty.FurnishingId = request.FurnishingId;
            updatedProperty.Furniture         = request.Furniture;
            updatedProperty.IsActive          = request.IsActive;
            updatedProperty.IsShared          = request.IsShared;
            updatedProperty.Laundry           = request.Laundry;
            updatedProperty.NumberOfBathrooms = request.NumberOfBathrooms;
            updatedProperty.NumberOfBedrooms  = request.NumberOfBedrooms;
            updatedProperty.NumberOfLayers    = request.NumberOfLayers;
            updatedProperty.NumberOfParking   = request.NumberOfParking;
            updatedProperty.Others            = request.Others;
            updatedProperty.PropertyBuildYear = request.PropertyBuildYear;
            updatedProperty.PropertyCity      = request.PropertyCity;
            updatedProperty.PropertyCountry   = request.PropertyCountry;
            updatedProperty.PropertyDesc      = request.PropertyDesc;
            //updatedProperty.PropertyLogoImgUrl = request.PropertyLogoImgUrl;
            //updatedProperty.PropertyManagerId = request.PropertyManagerId;
            updatedProperty.PropertyName          = request.PropertyName;
            updatedProperty.PropertyNumber        = request.PropertyNumber;
            updatedProperty.PropertyStateProvince = request.PropertyStateProvince;
            updatedProperty.PropertyStreet        = request.PropertyStreet;
            updatedProperty.PropertySuiteNumber   = request.PropertySuiteNumber;
            //updatedProperty.PropertyVideoUrl = request.PropertyVideoUrl;
            updatedProperty.PropertyZipPostCode = request.PropertyZipPostCode;
            updatedProperty.Refrigerator        = request.Refrigerator;
            updatedProperty.SecuritySystem      = request.SecuritySystem;
            updatedProperty.FeatureNotes        = request.FeatureNotes;

            updatedProperty.Status = request.Status.ToString(); //***************************************************************

            updatedProperty.Stove           = request.Stove;
            updatedProperty.TotalLivingArea = request.TotalLivingArea;
            updatedProperty.Tvinternet      = request.Tvinternet;

            updatedProperty.PropertyType1 = request.PropertyType1.ToString(); //***************************************************************
            updatedProperty.Type          = request.PropertyType1.ToString(); // new for client side rendering

            updatedProperty.UtilityIncluded = request.UtilityIncluded;
            updatedProperty.CreationDate    = ppt.Created.ToString("MMMM dd, yyyy");
            updatedProperty.CreatedDate     = ppt.Created.ToString("MMMM dd, yyyy"); //new for client side rendering

            updatedProperty.UpdateDate = updated.Modified.ToString("MMMM dd, yyyy");

            updatedProperty.OwnerList    = owners;
            updatedProperty.ContractList = contracts;

            try
            {
                await _context.SaveChangesAsync();

                // logging
                Log.Information("The property {PorpertyName} has been updated successfully", ppt.PropertyName);

                // Send messages if necessary

                PropertyUpdateEvent e = new PropertyUpdateEvent(Guid.NewGuid(), request.PropertyId, request.PropertyName,
                                                                request.PropertyBuildYear, request.PropertyType1.ToString(), request.BasementAvailable, request.IsShared, request.NumberOfBedrooms,
                                                                request.NumberOfBathrooms, request.NumberOfLayers, request.NumberOfParking, request.TotalLivingArea,
                                                                request.PropertyNumber + " " + request.PropertyStreet, request.PropertyCity, request.PropertyStateProvince, request.PropertyCountry,
                                                                request.PropertyZipPostCode);

                try
                {
                    await _messagePublisher.PublishMessageAsync(e.MessageType, e, "asset_created"); // publishing the message
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while publishing {MessageType} message with id {MessageId}.", e.MessageType, e.MessageId);
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error occured while deleting the image for the property {PropertyName}.", ppt.PropertyName);
            }

            return(updatedProperty);  //.true;
        }
Example #11
0
        public async Task UpdateAsync(EditPropertyInputModel input)
        {
            var property = this.propertiesRepository
                           .All()
                           .FirstOrDefault(p => input.Id == p.Id);

            property.Name        = input.Name;
            property.Floors      = input.Floors;
            property.Stars       = input.PropertyRating;
            property.Description = input.Description;

            var propertyRules = this.propertiesRepository
                                .AllWithDeleted()
                                .Where(p => p.Id == input.Id)
                                .Select(p => p.PropertyRules)
                                .FirstOrDefault();
            var rulesIds = input.RulesIds != null ? input.RulesIds : new List <int>();

            foreach (var propertyRule in propertyRules)
            {
                propertyRule.IsAllowed = rulesIds.Contains(propertyRule.RuleId) ? true : false;
            }

            var propertyFacilities = this.propertyFacilitiesRepository
                                     .AllWithDeleted()
                                     .Where(f => f.PropertyId == input.Id)
                                     .ToList();
            var facilitiesIds = input.FacilitiesIds != null ? input.FacilitiesIds : new List <int>();

            foreach (var facilityId in facilitiesIds)
            {
                var isNeededToBeAdded = !propertyFacilities.Any(f => f.FacilityId == facilityId);
                if (isNeededToBeAdded)
                {
                    var propertyFacility = new PropertyFacility
                    {
                        PropertyId = input.Id,
                        FacilityId = facilityId,
                    };

                    await this.propertyFacilitiesRepository.AddAsync(propertyFacility);

                    continue;
                }
                else
                {
                    var propertyFacility = propertyFacilities.FirstOrDefault(f => f.FacilityId == facilityId);
                    if (propertyFacility.IsDeleted == true)
                    {
                        this.propertyFacilitiesRepository.Undelete(propertyFacility);

                        continue;
                    }
                }
            }

            foreach (var propertyFacility in propertyFacilities)
            {
                var isNeededToBeDeleted = !facilitiesIds.Contains(propertyFacility.FacilityId);
                if (isNeededToBeDeleted)
                {
                    this.propertyFacilitiesRepository.Delete(propertyFacility);
                }
            }

            await this.propertyFacilitiesRepository.SaveChangesAsync();

            await this.propertiesRepository.SaveChangesAsync();
        }
Example #12
0
        public async Task CreateAsync(AddPropertyInputModel input, string userId, string imagePath)
        {
            var property = new Property
            {
                Name               = input.Name,
                Address            = input.Address,
                PropertyCategoryId = input.PropertyCategoryId,
                Floors             = input.Floors,
                Stars              = input.PropertyRating,
                TownId             = input.TownId,
                ApplicationUserId  = userId,
                Description        = input.Description,
            };

            var rules    = this.rulesRepository.All();
            var rulesIds = input.RulesIds != null ? input.RulesIds : new List <int>();

            foreach (var rule in rules)
            {
                var propertyRule = new PropertyRule
                {
                    Property  = property,
                    RuleId    = rule.Id,
                    IsAllowed = rulesIds.Contains(rule.Id),
                };

                property.PropertyRules.Add(propertyRule);
            }

            var facilitiesIds = input.FacilitiesIds;

            if (facilitiesIds != null)
            {
                foreach (var facilityId in facilitiesIds)
                {
                    var propertyFacility = new PropertyFacility
                    {
                        Property   = property,
                        FacilityId = facilityId,
                    };

                    property.PropertyFacilities.Add(propertyFacility);
                }
            }

            Directory.CreateDirectory(imagePath);
            if (input.Images != null && input.Images.Any())
            {
                foreach (var image in input.Images)
                {
                    var extension = Path.GetExtension(image.FileName).TrimStart('.');
                    if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                    {
                        throw new Exception($"{GlobalConstants.ErrorMessages.ImageExtention} {extension}");
                    }

                    var propertyImage = new PropertyImage
                    {
                        Extension = extension,
                    };
                    property.PropertyImages.Add(propertyImage);

                    var physicalPath = $"{imagePath}{propertyImage.Id}.{extension}";
                    using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
                    await image.CopyToAsync(fileStream);
                }
            }

            await this.propertiesRepository.AddAsync(property);

            await this.propertiesRepository.SaveChangesAsync();
        }