public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var property = _properties.GetById(id);

            if (property == null)
            {
                return(NotFound());
            }

            // Transposes data from model to view model
            PropertyDetailsViewModel propertyDetailModel = new PropertyDetailsViewModel
            {
                Id            = property.Id,
                Manager       = property.Manager,
                StreetAddress = property.StreetAddress,
                City          = property.City,
                Postcode      = property.Postcode,
                CostPM        = property.CostPM,
                Description   = property.Description,
                Available     = property.Available
            };

            return(View(propertyDetailModel));
        }
        public async Task <IActionResult> DetailsAsync(string id)
        {
            var model = await this.listingService.GetDetailsAsync(id);

            if (model == null)
            {
                return(this.NotFound());
            }

            var viewModel = new PropertyDetailsViewModel
            {
                Id          = model.Id,
                Name        = model.Name,
                OwnerName   = model.OwnerName,
                City        = model.City,
                Address     = model.Address,
                Country     = model.Country,
                Description = model.Description,
                Price       = model.Price,
                Status      = model.Status.ToString(),
                Category    = model.Category.ToString(),
                Image       = model.Image,
            };

            return(this.View(viewModel));
        }
        //GET: Property/Details/2
        public async Task <IActionResult> Details(int id)
        {
            var property = await _repo.Get(id);

            //var propertyView = _mapper.Map<PropertyViewModel>(property);
            var propOwn = await _siteUserManager.FindByIdAsync(property.PropertyOwnerId.ToString());

            PropertyDetailsViewModel propertyDetails = new PropertyDetailsViewModel
            {
                PropertyId                = property.PropertyId,
                PropertyOwnerId           = property.PropertyOwnerId,
                PropertyName              = property.PropertyName,
                PropertyAddress           = property.PropertyAddress,
                PropertyERF_LotNo         = property.PropertyERF_LotNo,
                PropertySGNo              = property.PropertySGNo,
                IsComplex                 = property.IsComplex,
                IsEstate                  = property.IsEstate,
                Complex_Estate_No         = property.Complex_Estate_No,
                PropertyOwnerFirstName    = propOwn.FirstName,
                PropertyOwnerLastName     = propOwn.LastName,
                PropertyOwnerEmailAddress = propOwn.Email,
                PropertyOwnerContactNo    = propOwn.PhoneNumber
            };

            return(View(propertyDetails));
        }
        public IActionResult GetDefaultValues()
        {
            var defaultValues = new PropertyDetailsViewModel {
                InterestRate = 2, RepaymentPeriod = 25
            };

            return(Ok(defaultValues));
        }
        public IActionResult GetMonthlyCost(PropertyDetailsViewModel model)
        {
            var accumalatedInterest = model.PropertyPrice ?? model.Amount * (model.InterestRate / 100);
            var totalCost           = ((model.PropertyPrice ?? model.Amount + accumalatedInterest) - model.Deposit) / model.RepaymentPeriod / 12;

            return(Ok(new {
                TotalCost = totalCost,
                AccumalatedInterest = accumalatedInterest / model.RepaymentPeriod
            }));
        }
        public async Task <IActionResult> Post([FromBody] PropertyDetailsViewModel value)
        {
            if (ModelState.IsValid)
            {
                var portfolioId = User.GetPortfolioId();
                await _propertyDataProvider.UpdateAsync(portfolioId, value);

                return(Ok());
            }

            return(BadRequest(new { Errors = ModelState.ToErrorCollection() }));
        }
        public async Task UpdateAsync(Guid portfolioId, PropertyDetailsViewModel viewModel)
        {
            var existingEntity = await Context.PropertyDetails.Where(details => details.PortfolioId == portfolioId && !details.IsDeleted)
                                 .FirstOrDefaultAsync(details => details.Id == viewModel.Id);

            if (existingEntity != null)
            {
                existingEntity.MapFrom(viewModel);
                Context.PropertyDetails.Update(existingEntity);
                await Context.SaveChangesAsync();
            }
        }