コード例 #1
0
        public async Task <bool> Handle(AddImageToPropertyCommand request, CancellationToken cancellationToken)
        {
            var file = request.PropertyImage;

            string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\");
            string url  = "images/" + file.FileName;

            if (file.Length > 0)
            {
                using (var fileStream = new FileStream(Path.Combine(path, file.FileName), FileMode.Create))
                {
                    try
                    {
                        await file.CopyToAsync(fileStream);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
            }

            var property = _context.Property.FirstOrDefault(p => p.Id == request.PropertyId);

            var image = property.AddImages(request.PropertyImgTitle, url, request.PropertyId);


            _context.Add(image);

            try
            {
                await _context.SaveChangesAsync();

                // logging
                Log.Information("An image for the property {PorpertyName} has been added successfully", property.PropertyName);

                // Send messages if necessary
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error occured while adding image to the property {PropertyName}.", property.PropertyName);
            }

            return(true);
        }
コード例 #2
0
        public async Task <AddOwnerToExistingPropertyCommandResult> Handle(AddOwnerToExistingPropertyCommand request, CancellationToken cancellationToken)
        {
            var property = _context.Property.FirstOrDefault(p => p.Id == request.PropertyId);

            PropertyOwner owner = null;

            var addedOwner = new AddOwnerToExistingPropertyCommandResult();

            // Check if the email already exist if adding new owner instead of existing owner
            //

            //var user = _context.PropertyOwner.FirstOrDefault(e => e.ContactEmail == request.ContactEmail);

            //if (user != null)
            //{
            //    return new AddOwnerToExistingPropertyCommandResult() { Notes = "The email already exists!"};
            //}

            // populate the addedOnwer
            addedOwner.UserAvartaImgUrl    = request.UserAvartaImgUrl;
            addedOwner.FirstName           = request.FirstName;
            addedOwner.LastName            = request.LastName;
            addedOwner.UserName            = request.UserName;
            addedOwner.ContactEmail        = request.ContactEmail;
            addedOwner.ContactTelephone1   = request.ContactTelephone1;
            addedOwner.ContactTelephone2   = request.ContactTelephone2;
            addedOwner.OnlineAccessEnbaled = request.OnlineAccessEnbaled;
            addedOwner.IsActive            = request.IsActive;
            addedOwner.RoleId       = request.RoleId;
            addedOwner.Notes        = request.Notes;
            addedOwner.StreetNumber = request.StreetNumber;
            addedOwner.City         = request.City;
            addedOwner.StateProv    = request.StateProv;
            addedOwner.ZipPostCode  = request.ZipPostCode;
            addedOwner.Country      = request.Country;
            addedOwner.Created      = DateTime.Now.ToString("MMMM dd, yyyy");
            addedOwner.Updated      = DateTime.Now.ToString("MMMM dd, yyyy");


            if (request.PropertyOwnerId == 0)
            {
                // Check if the email already exist if adding new owner instead of existing owner
                //

                var user = _context.PropertyOwner.FirstOrDefault(e => e.ContactEmail == request.ContactEmail);

                if (user != null)
                {
                    return(new AddOwnerToExistingPropertyCommandResult()
                    {
                        Notes = "The email already exists!"
                    });
                }

                var ownerAddress = new OwnerAddress(request.StreetNumber, request.City, request.StateProv, request.Country, request.ZipPostCode);

                owner = property.AddNewOwnerToProperty(request.PropertyId, request.UserName, request.FirstName, request.LastName, request.ContactEmail,
                                                       request.ContactTelephone1, request.ContactTelephone2, false, request.UserAvartaImgUrl, request.IsActive, 2, request.Notes, ownerAddress);

                _context.Add(owner);
            }
            else
            {
                owner = _context.PropertyOwner.Include(a => a.Address).FirstOrDefault(o => o.Id == request.PropertyOwnerId);

                var ownerProperty = property.AddExistingOwnerToProperty(owner, request.PropertyId);

                _context.Add(ownerProperty);
            }


            try
            {
                await _context.SaveChangesAsync();

                addedOwner.Id = owner.Id;


                // logging
                Log.Information("The new owner {OwnerName} has been added to the property {PorpertyName} successfully", request.FirstName + " " + request.LastName, property.PropertyName);

                // Send messages if necessary
                // Publish message to MQ for other service to consume

                AddOwnerEvent e = new AddOwnerEvent(new Guid(), owner.Id, request.PropertyId, owner.UserName, owner.FirstName, owner.LastName,
                                                    owner.ContactEmail, owner.ContactTelephone1, owner.ContactTelephone2, owner.OnlineAccess,
                                                    owner.UserAvartaImgUrl, owner.IsActive, owner.RoleId, owner.Notes, owner.Address.StreetNumber,
                                                    owner.Address.City, owner.Address.StateProvince, owner.Address.ZipPostCode, owner.Address.Country);


                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);
                }
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error occured while adding the new owner {OwnerName} to the property {PropertyName}.", request.FirstName + " " + request.LastName, property.PropertyName);
            }

            return(addedOwner);
        }
コード例 #3
0
        public async Task <ManagementContractDetailsViewModel> Handle(AddManagementContractCommand request, CancellationToken cancellationToken)
        {
            var property = _context.Property
                           .Include(p => p.ManagementContract)
                           .FirstOrDefault(p => p.Id == request.PropertyId);

            // Get existing contract
            //
            var existingContract = property.ManagementContract.FirstOrDefault(c => c.IsActive == true);

            if (existingContract != null)
            {
                // Deactivate the existing active contract
                //
                var updatedContract = property.UpdateManagementContractStatus(existingContract, false);

                _context.Update(updatedContract);



                //if (request.ManagementContractType.ToString() == "Renewal")
                //{
                //    // Deactivate the existing active contract
                //    //
                //    var updatedContract = property.UpdateManagementContractStatus(existingContract, false);

                //    _context.Update(updatedContract);

                //    // save to db aLL tegether at the end
                //    //

                //    //try
                //    //{
                //    //    await _context.SaveChangesAsync();
                //    //}
                //    //catch(Exception ex)
                //    //{
                //    //    //throw ex;
                //    //    Log.Error(ex, "Error occured while renewing management contract to the property {PropertyName}.", property.PropertyName);
                //    //}

                //    //return new ManagementContractDetailsViewModel() { };

                //}
                //else
                //{

                //}
            }



            var contract = property.AddManabgementContract(request.PropertyId, request.ManagementContractTitle, request.ManagementContractType,
                                                           request.StartDate, request.EndDate, request.PlacementFeeScale, request.ManagementFeeScale, request.SolicitingOnly,
                                                           request.ContractSignDate, true, request.Notes);

            _context.Add(contract);

            var newContract = new ManagementContractDetailsViewModel();



            try
            {
                await _context.SaveChangesAsync();

                //property.UpdateManagementContractStatus(existingContract, false); // disable the previous contract, use case: ownership change

                // map the return view model
                newContract.Id = contract.Id;
                newContract.ManagementContractTitle = request.ManagementContractTitle;
                newContract.StartDate          = request.StartDate.ToString("MMMM dd, yyyy");
                newContract.EndDate            = request.EndDate.ToString("MMMM dd, yyyy");
                newContract.ContractSignDate   = request.StartDate.ToString("MMMM dd, yyyy");
                newContract.ManagementFeeScale = request.ManagementFeeScale;
                newContract.PlacementFeeScale  = request.PlacementFeeScale;
                newContract.ManagemetnFeeNotes = request.Notes;
                newContract.PropertyName       = contract.Property.PropertyName;
                //newContract.PropertyStreet =
                newContract.Created  = DateTime.Now.ToString("MMMM dd, yyyy");
                newContract.Modified = DateTime.Now.ToString("MMMM dd, yyyy");

                // logging
                Log.Information("A management contract for the property {PorpertyName} has been added successfully", property.PropertyName);

                // Send messages if necessary, e.g send notificaiton to the contract signers, including owners and pms
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error occured while adding management contract to the property {PropertyName}.", property.PropertyName);
            }

            return(newContract);
        }