//GET : Property/Edit/id
        public async Task <IActionResult> Edit(int id)
        {
            var property = await _repo.Get(id);

            var model = _mapper.Map <PropertyViewModel>(property);

            var siteId            = User.GetUserSiteIdAsGuid();
            var propertyOwnerRole = await _appRoleRepo.GetPropertyOwnerRoleId(siteId);

            var propertyOwnerRoleId = propertyOwnerRole.Id;
            var propertyOwners      = await _appUserRoleRepo.GetAllPropertyOwners(propertyOwnerRoleId);

            //var propertyOwners = await _appUserRoleRepo.GetAllPropertyOwners();
            List <PropertyOwnerDDListViewModel> propertyOwnerSelectList = new List <PropertyOwnerDDListViewModel> {
            };

            foreach (var propertyOwner in propertyOwners)
            {
                var propertyOwnerId   = propertyOwner.UserId;
                var propertyOwnerItem = await _siteUserManager.FindByIdAsync(propertyOwnerId.ToString());

                var propOwnerListItem = new PropertyOwnerDDListViewModel
                {
                    PropertyOwnerId = propertyOwnerId.ToString(),
                    FirstName       = propertyOwnerItem.FirstName,
                    LastName        = propertyOwnerItem.LastName
                };
                propertyOwnerSelectList.Add(propOwnerListItem);
            }

            //Put Property Owners in a Select List.
            //set up config for this , include correct packages.
            try
            {
                if (User.IsInRole("Draughtsman"))
                {
                    var userEmail       = User.GetEmail();
                    var userDisplayName = User.GetEmail();
                    //   var siteId = User.GetUserSiteIdAsGuid();

                    /*KEEPING THIS HERE .. This snippet will give you all clients with properties
                     * COULD BE HANDY FOR YOU FICK If the two ever diverge - doubt it backup if the other code fails
                     * var PropertyOwnerProperties = await _repo.GetAll();
                     * var PropertyOwnerPropertiesList = PropertyOwnerProperties.ToList();*/

                    var propertyOwnerSelect = propertyOwnerSelectList.Select(n => new SelectListItem
                    {
                        Text  = n.FirstName + n.LastName,
                        Value = n.PropertyOwnerId //check the conversion back to GUID below
                    });
                    var createmodel = new CreatePropertyViewModel
                    {
                        PropertyId        = model.PropertyId,
                        PropertyName      = model.PropertyName,
                        PropertyAddress   = model.PropertyAddress,
                        PropertySGNo      = model.PropertySGNo,
                        PropertyERF_LotNo = model.PropertyERF_LotNo,
                        PropertyOwnerId   = model.PropertyOwnerId,
                        PropertyOwners    = propertyOwnerSelect
                    };
                    return(View(createmodel));
                }
                ;
            }
            catch
            {
            }
            return(View(model));
        }
        public async Task <IActionResult> Create()
        {
            var userId = User.GetUserIdAsGuid();
            var siteId = User.GetUserSiteIdAsGuid();

            //Get All Users in Property Owner Role
            //var propertyOwners = await _projectRepo.getAllPropertyOwners();
            var propertyOwnerRole = await _appRoleRepo.GetPropertyOwnerRoleId(siteId);

            var propertyOwnerRoleId = propertyOwnerRole.Id;
            var propertyOwners      = await _appUserRoleRepo.GetAllPropertyOwners(propertyOwnerRoleId);

            //  var propertyOwnersList = propertyOwners.ToList();
            List <PropertyOwnerDDListViewModel> propertyOwnerSelectList = new List <PropertyOwnerDDListViewModel> {
            };

            foreach (var propertyOwner in propertyOwners)
            {
                var propertyOwnerId   = propertyOwner.UserId;
                var propertyOwnerItem = await _siteUserManager.FindByIdAsync(propertyOwnerId.ToString());

                var propOwnerListItem = new PropertyOwnerDDListViewModel
                {
                    PropertyOwnerId = propertyOwnerId.ToString(),
                    FirstName       = propertyOwnerItem.FirstName,
                    LastName        = propertyOwnerItem.LastName
                };
                propertyOwnerSelectList.Add(propOwnerListItem);
            }

            //Put Property Owners in a Select List.
            //set up config for this , include correct packages.
            try
            {
                if (User.IsInRole("Draughtsman"))
                {
                    var userEmail       = User.GetEmail();
                    var userDisplayName = User.GetEmail();

                    /*KEEPING THIS HERE .. This snippet will give you all clients with properties
                     * COULD BE HANDY FOR YOU FICK If the two ever diverge - doubt it backup if the other code fails
                     * var PropertyOwnerProperties = await _repo.GetAll();
                     * var PropertyOwnerPropertiesList = PropertyOwnerProperties.ToList();*/

                    var propertyOwnerSelect = propertyOwnerSelectList.Select(n => new SelectListItem
                    {
                        Text  = n.FirstName + n.LastName,
                        Value = n.PropertyOwnerId //check the conversion back to GUID below
                    });
                    var createmodel = new CreatePropertyViewModel
                    {
                        PropertyOwners = propertyOwnerSelect
                    };
                    return(View(createmodel));
                }
                ;
            }
            catch
            {
                throw new AccessViolationException("User not a Authorized");
            }

            return(RedirectToAction("Index", "Home", new { userId }));
        }