Example #1
0
        public async Task UpdateAsync(Guid portfolioId, ShortlistedPropertyViewModel viewModel)
        {
            var existingEntity = await Context.ShortlistedProperties.FirstOrDefaultAsync(c => c.PortfolioId == portfolioId && !c.IsDeleted && c.Id == viewModel.ShortlistedPropertyId);

            if (existingEntity != null)
            {
                existingEntity.MapFrom(viewModel);
                Context.ShortlistedProperties.Update(existingEntity);
                await Context.SaveChangesAsync();
            }
            else
            {
                var newEntity = new ShortlistedProperty
                {
                    Address = viewModel.Address,
                    Created = DateTime.Now,
                    Deposit = viewModel.Deposit,
                    ExpectedRentalIncome = viewModel.ExpectedRentalIncome,
                    Fees                 = viewModel.Fees,
                    Insurance            = viewModel.Insurance,
                    LettableUnits        = viewModel.LettableUnits,
                    ManagementCost       = viewModel.ManagementCost,
                    MortgageInterestRate = viewModel.MortgageInterestRate,
                    PortfolioId          = portfolioId,
                    PricePaid            = viewModel.PricePaid,
                    Reference            = viewModel.Reference,
                    RepairsContingency   = viewModel.RepairsContingency,
                    ServiceCharge        = viewModel.ServiceCharge
                };

                await Context.ShortlistedProperties.AddAsync(newEntity);

                await Context.SaveChangesAsync();
            }
        }
        public ShortlistedPropertyViewModel(ShortlistedProperty shortlistedProperty)
        {
            if (shortlistedProperty == null)
            {
                return;
            }

            ShortlistedPropertyId = shortlistedProperty.Id;
            Reference             = shortlistedProperty.Reference;
            Address              = shortlistedProperty.Address;
            PricePaid            = shortlistedProperty.PricePaid;
            Deposit              = shortlistedProperty.Deposit;
            Fees                 = shortlistedProperty.Fees;
            LettableUnits        = shortlistedProperty.LettableUnits;
            ExpectedRentalIncome = shortlistedProperty.ExpectedRentalIncome;
            MortgageInterestRate = shortlistedProperty.MortgageInterestRate;
            ManagementCost       = shortlistedProperty.ManagementCost;
            RepairsContingency   = shortlistedProperty.RepairsContingency;
            ServiceCharge        = shortlistedProperty.ServiceCharge;
            Insurance            = shortlistedProperty.Insurance;
        }