Esempio n. 1
0
        public ActionResult Edit(int?id)
        {
            Session["InsertProperty"] = false;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (_db.HomeProperties.Any(a => a.HomePropertyID == id))
            {
                var homeProperty = _db.HomeProperties.Find(id);
                if (homeProperty == null)
                {
                    return(HttpNotFound());
                }


                var facilityList = homeProperty.HomeProperties_MetaData.Where(a => a.FacilityID != null && a.ConditionID == null).Select(c => c.FacilityID).ToList();
                ViewBag.SelectedFacilities = (from facility in _db.Facilities
                                              where facilityList.Contains(facility.FacilityID)
                                              select facility).ToList();
                var conditionList = homeProperty.HomeProperties_MetaData.Where(a => a.FacilityID == null && a.ConditionID != null).Select(c => c.ConditionID).ToList();
                ViewBag.SelectedConditions = (from condition in _db.Conditions
                                              where conditionList.Contains(condition.ConditionID)
                                              select condition).ToList();

                ViewBag.SelectedImage = homeProperty.HomeProperty_Galleries.ToList();

                CreatePropertyViewModel _createPropertyViewModel = new CreatePropertyViewModel()
                {
                    CityID         = homeProperty.Rigion.CityID,
                    CountryID      = homeProperty.Rigion.City.CountryID,
                    Description    = homeProperty.Description,
                    HomePrice      = homeProperty.HomePrice.ToString(),
                    MortgagePrice  = homeProperty.MortgagePrice.ToString(),
                    PropertyTypeID = homeProperty.PropertyTypeID ?? 0,
                    RentPrice      = homeProperty.RentPrice.ToString(),
                    ImageName      = homeProperty.ImageName,
                    rigionID       = homeProperty.RegionID ?? 0,
                    rigionTitle    = homeProperty.Rigion.RegionTitle,
                    LocAge         = homeProperty.LocAge.ToString(),
                    LocArea        = homeProperty.LocArea.ToString(),
                    SubUsageID     = homeProperty.SubUsageID ?? 0,
                    usageID        = homeProperty.SubUsage.UsageID,
                    Title          = homeProperty.Title,
                    LocLatitude    = homeProperty.LocLatitude,
                    LocLongitude   = homeProperty.LocLongitude,
                    homePropertyId = homeProperty.HomePropertyID,
                    PhoneNum       = homeProperty.PhoneNum
                };

                ViewBag.CountryID      = new SelectList(_db.Countries, "CountryID", "CountryTitle");
                ViewBag.PropertyTypeID = new SelectList(_db.HomeProperty_Type, "PropertyTypeID", "Title");
                ViewBag.usageID        = new SelectList(_db.Usages, "UsageID", "UsageTitle");
                ViewBag.Facilities     = _db.Facilities.ToList();
                ViewBag.Conditions     = _db.Conditions.ToList();
                return(View(_createPropertyViewModel));
            }
            return(HttpNotFound());
        }
Esempio n. 2
0
        public ActionResult Create()
        {
            var viewModel = new CreatePropertyViewModel();

            viewModel.PossiblePropertyTypes = new string[] { "House", "Flat", "Bungalow" }
            .Select(x => new SelectListItem {
                Value = x, Text = x
            })
            .AsEnumerable();

            return(View(viewModel));
        }
Esempio n. 3
0
        public ActionResult Create()
        {
            var viewModel = new CreatePropertyViewModel();

            // TODO: an improvement is to use an enumeration for the property types
            viewModel.PossiblePropertyTypes = new string[] { "House", "Flat", "Bungalow" }
            .Select(x => new SelectListItem {
                Value = x, Text = x
            })
            .AsEnumerable();

            return(View(viewModel));
        }
        //[Authorize(Roles = "Owner")]
        // GET: VacProperties/Create
        public ActionResult Create()
        {
            ViewBag.CityId     = new SelectList(db.Cities, "Id", "Name");
            ViewBag.LocationId = new SelectList(db.Locations, "Id", "Address");

            var vproperty = new VacProperty();

            vproperty.Amenities = new List <Amenity>();
            PopulateSelectedAmenities(vproperty);
            var vmcreateproperty = new CreatePropertyViewModel();

            vmcreateproperty.CitiesSelectListItems = new SelectList(db.Cities, "Id", "Name");
            return(View(vmcreateproperty));
        }
Esempio n. 5
0
        public virtual ActionResult UploadAction(CreatePropertyViewModel _createPropertyViewModel, List <HttpPostedFileBase> fileUpload, List <string> my)
        {
            // Your Code - / Save Model Details to DB

            // Handling Attachments -
            //foreach (HttpPostedFileBase item in fileUpload)
            //{
            //    if (Array.Exists(model.FilesToBeUploaded.Split(','), s => s.Equals(item.FileName)))
            //    {
            //        //Save or do your action -  Each Attachment ( HttpPostedFileBase item )
            //    }
            //}
            return(View("Index"));
        }
        public ActionResult Create(CreatePropertyViewModel newProperty)
        {
            //Validate that required Fields are filled in
            if (!ModelState.IsValid)
            {
                return(View(newProperty));
            }

            //Create an instance of DBContext
            using (RateMyLandlordDbContext context = new RateMyLandlordDbContext())
            {
                //Make sure the new Property is Unique by comparing addresses.
                if (context.Properties.Any(row => row.Unit.Equals(newProperty.Unit)) &&
                    context.Properties.Any(row => row.Building.Equals(newProperty.Building)) &&
                    context.Properties.Any(row => row.Street.Equals(newProperty.Street)) &&
                    context.Properties.Any(row => row.City.Equals(newProperty.City)) &&
                    context.Properties.Any(row => row.Region.Equals(newProperty.Region)) &&
                    context.Properties.Any(row => row.Country.Equals(newProperty.Country)) &&
                    context.Properties.Any(row => row.ZipCode.Equals(newProperty.ZipCode))
                    )
                {
                    ModelState.AddModelError("", "This Property already exists.");
                    return(View());
                }
                //Create UserDTO
                Property newPropertyDTO = new Models.Data.Property()
                {
                    Name              = newProperty.Name,
                    Unit              = newProperty.Unit,
                    Building          = newProperty.Building,
                    Street            = newProperty.Street,
                    City              = newProperty.City,
                    Region            = newProperty.Region,
                    Country           = newProperty.Country,
                    ZipCode           = newProperty.ZipCode,
                    Rating            = newProperty.Rating,
                    RatingDescription = newProperty.RatingDescription,
                    Description       = newProperty.Description
                };
                //Add to context
                newPropertyDTO = context.Properties.Add(newPropertyDTO);
                // Save Changes
                context.SaveChanges();
            }

            //Redirect to Properties page.
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(CreatePropertyViewModel createproperty, double?lat, double?lng, string[] selectedAmenities)
        {
            if (selectedAmenities != null)
            {
                createproperty.VacProperty.Amenities = new List <Amenity>();
                foreach (var amenity in selectedAmenities)
                {
                    var amenityToAdd = db.Amenities.Find(int.Parse(amenity));
                    createproperty.VacProperty.Amenities.Add(amenityToAdd);
                }
            }

            if (ModelState.IsValid)
            {
                Location location = db.Locations
                                    .Include(l => l.City)
                                    .Where(l => l.CityId == createproperty.Location.CityId)
                                    .Where(l => l.ZIPCode.Equals(createproperty.Location.ZIPCode))
                                    .Where(l => l.Address.Equals(createproperty.Location.Address))
                                    .FirstOrDefault();

                if (location == null)
                {
                    createproperty.Location.LatCoordinate = lat;
                    createproperty.Location.LngCoordinate = lng;
                    db.Locations.Add(createproperty.Location);
                }
                else
                {
                    createproperty.Location = location;
                }

                //var currentUserId = User.Identity.GetUserId();
                createproperty.VacProperty.ApplicationUser = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);

                createproperty.VacProperty.LocationId = createproperty.Location.Id;
                db.VacProperties.Add(createproperty.VacProperty);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            PopulateSelectedAmenities(createproperty.VacProperty);
            ViewBag.CityId = new SelectList(db.Regions, "Id", "Name", createproperty.VacProperty.Location.CityId);
            return(View(createproperty.VacProperty));
        }
        public IHttpActionResult Post(CreatePropertyViewModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var propertyData = new Property();

            AutoMapper.Mapper.Map(createModel, propertyData);
            _propertyService.AddProperty(propertyData);


            var propertyViewModel = new PropertyViewModel();

            AutoMapper.Mapper.Map(propertyData, propertyViewModel);

            return(Created(
                       new Uri(Request.RequestUri + "api/properties" + propertyViewModel.Id),
                       propertyViewModel));
        }
Esempio n. 9
0
        public ActionResult Edit(CreatePropertyViewModel _createPropertyViewModel, List <int> checkFacility, List <int> checkCondition, List <HttpPostedFileBase> fileUpload, List <string> DeletedPhotp)
        {
            decimal homeprice     = 0;
            decimal rentPrice     = 0;
            decimal mortgagePrice = 0;
            int     locArea       = 0;
            int     locAge        = 0;
            string  _lat          = "";
            string  _long         = "";

            if (!string.IsNullOrEmpty(_createPropertyViewModel.HomePrice))
            {
                if (_createPropertyViewModel.HomePrice.Contains(','))
                {
                    homeprice = decimal.Parse(_createPropertyViewModel.HomePrice.Replace(",", ""));
                }
                else
                {
                    homeprice = decimal.Parse(_createPropertyViewModel.HomePrice);
                }
            }
            if (!string.IsNullOrEmpty(_createPropertyViewModel.RentPrice))
            {
                if (_createPropertyViewModel.RentPrice.Contains(','))
                {
                    rentPrice = decimal.Parse(_createPropertyViewModel.RentPrice.Replace(",", ""));
                }
                else
                {
                    rentPrice = decimal.Parse(_createPropertyViewModel.RentPrice);
                }
            }
            if (!string.IsNullOrEmpty(_createPropertyViewModel.MortgagePrice))
            {
                if (_createPropertyViewModel.MortgagePrice.Contains(','))
                {
                    mortgagePrice = decimal.Parse(_createPropertyViewModel.MortgagePrice.Replace(",", ""));
                }
                else
                {
                    mortgagePrice = decimal.Parse(_createPropertyViewModel.MortgagePrice);
                }
            }
            if (!string.IsNullOrEmpty(_createPropertyViewModel.LocArea))
            {
                if (_createPropertyViewModel.LocArea.Contains(','))
                {
                    locArea = int.Parse(_createPropertyViewModel.LocArea.Replace(",", ""));
                }
                else
                {
                    locArea = int.Parse(_createPropertyViewModel.LocArea);
                }
            }
            if (!string.IsNullOrEmpty(_createPropertyViewModel.LocAge))
            {
                if (_createPropertyViewModel.LocAge.Contains(','))
                {
                    locAge = int.Parse(_createPropertyViewModel.LocAge.Replace(",", ""));
                }
                else
                {
                    locAge = int.Parse(_createPropertyViewModel.LocAge);
                }
            }

            int           _cultureID = 1;
            int           UserID     = 1;
            List <string> ImageNames = new List <string>();

            if (User.Identity.IsAuthenticated)
            {
                var res = _db.Users.SingleOrDefault(a => a.UserName == User.Identity.Name);
                if (res != null)
                {
                    UserID = res.UserID;
                }
            }

            switch (System.Globalization.CultureInfo.CurrentCulture.Name)
            {
            case "fa-IR":
            {
                _cultureID = 1;
                break;
            }

            case "en-US":
            {
                _cultureID = 2;
                break;
            }
            }
            if (_createPropertyViewModel.PropertyTypeID == 1)
            {
                rentPrice     = 0;
                mortgagePrice = 0;
            }
            else
            {
                homeprice = 0;
            }
            var _homeProperty = _db.HomeProperties.Find(_createPropertyViewModel.homePropertyId);

            if (fileUpload[0] == null)
            {
                _createPropertyViewModel.ImageName = _homeProperty.ImageName;
                //_createPropertyViewModel.ImageName = "home-defualt.png";
                //ImageNames.Add(_createPropertyViewModel.ImageName);
            }
            else
            {
                _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fileUpload[0].FileName);
                fileUpload[0].SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName);
                ImageResizer img = new ImageResizer();
                img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName,
                           Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName);
            }

            if (!string.IsNullOrEmpty(_createPropertyViewModel.latlongMap))
            {
                _lat  = _createPropertyViewModel.latlongMap.Split(',')[0];
                _long = _createPropertyViewModel.latlongMap.Split(',')[1];
            }
            else
            {
                _lat  = _homeProperty.LocLatitude;
                _long = _homeProperty.LocLongitude;
            }

            _homeProperty.CreateDate     = DateTime.Now;
            _homeProperty.Title          = _createPropertyViewModel.Title;
            _homeProperty.CreateUserID   = UserID;
            _homeProperty.SubUsageID     = _createPropertyViewModel.SubUsageID;
            _homeProperty.StatusID       = (_createPropertyViewModel.PropertyTypeID == 1 ? 1 : 2);
            _homeProperty.RegionID       = _createPropertyViewModel.rigionID;
            _homeProperty.CultureID      = _cultureID;
            _homeProperty.PropertyTypeID = _createPropertyViewModel.PropertyTypeID;
            _homeProperty.LocAge         = locAge;
            _homeProperty.LocArea        = locArea;
            _homeProperty.Description    = _createPropertyViewModel.Description;
            _homeProperty.HomePrice      = homeprice;
            _homeProperty.MortgagePrice  = mortgagePrice;
            _homeProperty.RentPrice      = rentPrice;
            _homeProperty.ImageName      = _createPropertyViewModel.ImageName;
            _homeProperty.LocLatitude    = _lat;
            _homeProperty.LocLongitude   = _long;
            _homeProperty.PhoneNum       = _createPropertyViewModel.PhoneNum;

            if (ModelState.IsValid)
            {
                _db.Entry(_homeProperty).State = System.Data.Entity.EntityState.Modified;

                //_db.HomeProperties.Add(_homeProperty);


                if (fileUpload != null)
                {
                    foreach (var item in fileUpload)
                    {
                        if (item != null && item.IsImage())
                        {
                            if (DeletedPhotp != null)
                            {
                                if (DeletedPhotp.Contains(item.FileName))
                                {
                                    continue;
                                }
                            }
                            _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(item.FileName);
                            ImageNames.Add(_createPropertyViewModel.ImageName);
                            item.SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName);
                            ImageResizer img = new ImageResizer();
                            img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName,
                                       Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName);
                        }
                    }
                }


                #region facility
                _db.HomeProperties_MetaData.Where(a => a.HomePropertyID == _homeProperty.HomePropertyID).ToList().ForEach(a => _db.HomeProperties_MetaData.Remove(a));
                if (checkFacility != null)
                {
                    foreach (var item in checkFacility)
                    {
                        _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData()
                        {
                            HomePropertyID = _homeProperty.HomePropertyID,
                            FacilityID     = item
                        });
                    }
                }
                #endregion

                #region condition
                _db.HomeProperties_MetaData.Where(a => a.HomePropertyID == _homeProperty.HomePropertyID).ToList().ForEach(a => _db.HomeProperties_MetaData.Remove(a));
                if (checkCondition != null)
                {
                    foreach (var item in checkCondition)
                    {
                        _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData()
                        {
                            HomePropertyID = _homeProperty.HomePropertyID,
                            ConditionID    = item
                        });
                    }
                }
                #endregion

                #region ImageGallry
                if (ImageNames != null)
                {
                    foreach (var item in ImageNames)
                    {
                        _db.HomeProperty_Galleries.Add(new HomeProperty_Galleries()
                        {
                            HomePropertyID = _homeProperty.HomePropertyID,
                            ImageName      = item
                        });
                    }
                }
                #endregion
                _db.SaveChanges();
                Session["InsertProperty"] = true;
                ModelState.Clear();
            }
            else
            {
                Session["NoInsertData"] = true;
            }
            ViewBag.CountryID      = new SelectList(_db.Countries, "CountryID", "CountryTitle");
            ViewBag.PropertyTypeID = new SelectList(_db.HomeProperty_Type, "PropertyTypeID", "Title");
            ViewBag.usageID        = new SelectList(_db.Usages, "UsageID", "UsageTitle");
            ViewBag.Facilities     = _db.Facilities.ToList();
            ViewBag.Conditions     = _db.Conditions.ToList();
            return(RedirectToAction("PropertyList", "Property", new { area = "UserPanel" }));
        }
Esempio n. 10
0
        public virtual ActionResult testCreate3(CreatePropertyViewModel _createPropertyViewModel, List <int> checkFacility, List <int> checkCondition, List <HttpPostedFileBase> fileUpload, List <string> DeletedPhotp)
        {
            //int _cultureID = 1;
            //int UserID = 1;
            //List<string> ImageNames = new List<string>();
            //if (User.Identity.IsAuthenticated)
            //{
            //    var res = _db.Users.SingleOrDefault(a => a.UserName == User.Identity.Name);
            //    if (res != null)
            //        UserID = res.UserID;
            //}
            //if (fileUpload[0] == null)
            //{
            //    _createPropertyViewModel.ImageName = "home-defualt.png";
            //    ImageNames.Add(_createPropertyViewModel.ImageName);
            //}
            //else
            //{
            //    _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fileUpload[0].FileName);
            //    fileUpload[0].SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName);
            //    ImageResizer img = new ImageResizer();
            //    img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName,
            //    Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName);
            //}
            //switch (System.Globalization.CultureInfo.CurrentCulture.Name)
            //{
            //    case "fa-IR":
            //        {
            //            _cultureID = 1;
            //            break;
            //        }

            //    case "en-US":
            //        {
            //            _cultureID = 2;
            //            break;
            //        }

            //}
            //if (_createPropertyViewModel.PropertyTypeID == 1)
            //{
            //    _createPropertyViewModel.RentPrice = 0;
            //    _createPropertyViewModel.MortgagePrice = 0;
            //}
            //else
            //{
            //    _createPropertyViewModel.HomePrice = 0;
            //}
            //HomeProperty _homeProperty = new HomeProperty()
            //{
            //    CreateDate = DateTime.Now,
            //    Title = _createPropertyViewModel.Title,
            //    CreateUserID = UserID,
            //    SubUsageID = _createPropertyViewModel.SubUsageID,
            //    StatusID = 1,
            //    RegionID = _createPropertyViewModel.rigionID,
            //    CultureID = _cultureID,
            //    PropertyTypeID = _createPropertyViewModel.PropertyTypeID,
            //    LocAge = _createPropertyViewModel.LocAge,
            //    LocArea = _createPropertyViewModel.LocArea,
            //    Description = _createPropertyViewModel.Description,
            //    HomePrice = _createPropertyViewModel.HomePrice,
            //    MortgagePrice = _createPropertyViewModel.MortgagePrice,
            //    RentPrice = _createPropertyViewModel.RentPrice,
            //    ImageName = _createPropertyViewModel.ImageName
            //};
            //if (ModelState.IsValid)
            //{
            //    _db.HomeProperties.Add(_homeProperty);
            //    _db.SaveChanges();

            //    if (fileUpload != null)
            //    {
            //        foreach (var item in fileUpload)
            //        {
            //            if (item != null && item.IsImage())
            //            {
            //                if (DeletedPhotp != null)
            //                {
            //                    if (DeletedPhotp.Contains(item.FileName))
            //                    {
            //                        continue;
            //                    }

            //                }
            //                _createPropertyViewModel.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(item.FileName);
            //                ImageNames.Add(_createPropertyViewModel.ImageName);
            //                item.SaveAs(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName);
            //                ImageResizer img = new ImageResizer();
            //                img.Resize(Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/") + _createPropertyViewModel.ImageName,
            //                Server.MapPath("/Areas/UserPanel/HomePropertyUploadImages/Thumb/") + _createPropertyViewModel.ImageName);

            //            }

            //        }
            //    }

            //    #region facility
            //    if (checkFacility!= null)
            //    {
            //        foreach (var item in checkFacility)
            //        {
            //            _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData()
            //            {
            //                HomePropertyID = _homeProperty.HomePropertyID,
            //                FacilityID = item
            //            });
            //        }
            //    }
            //    #endregion

            //    #region condition
            //    if (checkCondition != null)
            //    {
            //        foreach (var item in checkCondition)
            //        {
            //            _db.HomeProperties_MetaData.Add(new HomeProperties_MetaData()
            //            {
            //                HomePropertyID = _homeProperty.HomePropertyID,
            //                ConditionID = item
            //            });
            //        }
            //    }
            //    #endregion

            //    #region ImageGallry
            //    if (ImageNames != null)
            //    {
            //        foreach (var item in ImageNames)
            //        {
            //            _db.HomeProperty_Galleries.Add(new HomeProperty_Galleries()
            //            {
            //                HomePropertyID = _homeProperty.HomePropertyID,
            //                ImageName = item
            //            });
            //        }
            //    }
            //    #endregion
            //    _db.SaveChanges();
            //    Session["InsertProperty"] = true;
            //    ModelState.Clear();
            //}
            //ViewBag.CountryID = new SelectList(_db.Countries, "CountryID", "CountryTitle");
            //ViewBag.PropertyTypeID = new SelectList(_db.HomeProperty_Type, "PropertyTypeID", "Title");
            //ViewBag.usageID = new SelectList(_db.Usages, "UsageID", "UsageTitle");
            //ViewBag.Facilities = _db.Facilities.ToList();
            //ViewBag.Conditions = _db.Conditions.ToList();

            return(View());
        }
Esempio n. 11
0
 public virtual ActionResult testCreate2(CreatePropertyViewModel _createPropertyViewModel)
 {
     ViewBag.City = new SelectList(_db.Cities, "CityID", "CityTitle");
     return(View());
 }
Esempio n. 12
0
 public virtual ActionResult testCreate(CreatePropertyViewModel _createPropertyViewModel, int City)
 {
     return(View());
 }
        //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 }));
        }