/// <summary> /// This is the logic for Adding a new Property in our Database it's simple as it's look. /// </summary> /// <param name="model"></param> public void AddProperty(PropertyFormViewModel model) { Property property = Mapper.Map <Property>(model); property.Owner = this.Context.Landlords.FirstOrDefault(m => m.Id == model.LandlordId); this.Context.Properties.Add(property); this.Context.SaveChanges(); }
public ActionResult Create() { var viewModel = new PropertyFormViewModel { Statuses = _context.Statuses.ToList(), Types = _context.Types.ToList() }; return(View(viewModel)); }
public ActionResult EditProperty([Bind(Exclude = "LandlordsList, LandlordId")] PropertyFormViewModel property) { if (ModelState.IsValid) { this.service.EditProperty(property); return(this.RedirectToAction($"Show/Rent", "Properties", new { area = "" })); } return(this.View(property)); }
public ActionResult EditProperty(int id) { PropertyFormViewModel property = this.service.EditPropertyById(id); if (property == null) { return(this.HttpNotFound()); } return(this.View(property)); }
public async Task <IActionResult> Add(PropertyFormViewModel model) { bool isRoomTypeExist = this.propertyServce.IsRoomTypeExists((int)model.RoomType); if (!isRoomTypeExist) { ModelState.AddModelError(nameof(model.RoomType), "Please select valid RoomType"); } bool isCityExist = await this.locationService.ExistAsync(model.CityId); if (!isCityExist) { ModelState.AddModelError(nameof(model.CityId), "Please select a valid City"); } bool isCityContainsSection = await this.locationService.ContainsSectionAsync(model.CityId, model.LocationId); if (!isCityContainsSection) { ModelState.AddModelError(nameof(model.LocationId), "That Location is not part of the selected city"); } if (!ModelState.IsValid) { var cities = await this.GetCitiesAsync(); var locations = await GetLocationsAsync(); return(View(new PropertyFormViewModel { Cities = cities, Locations = locations })); } await this.propertyServce .CreateAsync(model.Title, model.Description, model.Price, model.Space, model.RoomType, model.IsForRent, model.CityId, model.LocationId, model.HomeImage, model.HomeSecondaryImage); TempData.AddSuccessMessage($"The Home {model.Title} has been created succesfully"); return(RedirectToAction(nameof(ListAll))); }
public ActionResult Add([Bind(Include = "FullAddress, ApartmentSize, NumberOfRooms, IsActive, Type, UrlPicture, Price, LandlordId")] PropertyFormViewModel propertyFormViewModelgModel, HttpPostedFileBase upload) { if (ModelState.IsValid) { this.propertyService.AddProperty(propertyFormViewModelgModel); return(this.RedirectToAction("Index", "ControlPanel")); } PropertyFormViewModel model = this.propertyService.GeneratePropertyViewModel(); return(this.View(model)); }
public ActionResult Create() { var PropertyTypes = _context.PropertyTypess.ToList(); var image = _context.Images.ToList(); var viewModel = new PropertyFormViewModel { Property = new PropertyProfile(), KindsOfProperty = PropertyTypes, image = image }; return(View("Create", viewModel)); }
public PropertyFormViewModel GeneratePropertyViewModel() { PropertyFormViewModel model = new PropertyFormViewModel(); List <LandlordViewModel> landlordList = new List <LandlordViewModel>(); foreach (var landlord in this.Context.Landlords) { LandlordViewModel lvm = Mapper.Map <Landlord, LandlordViewModel>(landlord); landlordList.Add(lvm); } model.LandlordsList = landlordList; return(model); }
/// <summary> /// Here we fetch our data from the Database by ID and return the model with his data to be Edited, Also we use AutoMapper to Map or Entity models to our View/Binding Models. /// </summary> /// <param name="id"></param> /// <returns></returns> public PropertyFormViewModel EditPropertyById(int id) { var property = this.Context.Properties.Find(id); PropertyFormViewModel model = Mapper.Map <Property, PropertyFormViewModel>(property); List <LandlordViewModel> landlordList = new List <LandlordViewModel>(); foreach (var landlord in this.Context.Landlords) { LandlordViewModel lvm = Mapper.Map <Landlord, LandlordViewModel>(landlord); landlordList.Add(lvm); } model.LandlordsList = landlordList; return(model); }
public ActionResult Create(PropertyFormViewModel createProperty) { var property = Mapper.Map <PropertyFormViewModel, Property>(createProperty); if (ModelState.IsValid) { propertyService.CreateProperty(property); TempData.Add("flash", new FlashSuccessViewModel("Your property details have been created successfully.")); return(RedirectToAction("Edit", new { id = property.Id })); } else { TempData.Add("flash", new FlashDangerViewModel("There was an error saving property")); } return(View(createProperty)); }
public ActionResult Edit(int id) { var property = _context.PropertyProfiles.SingleOrDefault(c => c.ID == id); if (property == null) { return(HttpNotFound()); } var viewModel = new PropertyFormViewModel { Property = property, KindsOfProperty = _context.PropertyTypess.ToList() }; return(View("Create", viewModel)); }
/// <summary> /// Here we set the new Data Manualy. /// </summary> /// <returns></returns> public void EditProperty(PropertyFormViewModel model) { var propertyToEdit = this.Context.Properties.Find(model.Id); if (propertyToEdit != null) { propertyToEdit.Type = model.Type; propertyToEdit.ApartmentSize = model.ApartmentSize; propertyToEdit.FullAddress = model.FullAddress; propertyToEdit.IsActive = model.IsActive; propertyToEdit.NumberOfRooms = model.NumberOfRooms; propertyToEdit.Price = model.Price; //propertyToEdit.UrlPicture = model.UrlPicture; } this.Context.SaveChanges(); }
[HttpPost] //action to be called only by HTTPPOST method public ActionResult Create(PropertyFormViewModel viewModel) { if (!ModelState.IsValid) { viewModel.Types = _context.Types.ToList(); viewModel.Statuses = _context.Statuses.ToList(); return(View("Create", viewModel)); } #region Refactored Code ////convert the PropertyViewModel to a property object, add it to the _context and save the changes. //var manager = _context.Users.Single(u => u.Id == managerId); //var status = _context.Statuses.Single(s => s.Id == viewModel.Status); //var type = _context.Types.Single(t => t.Id == viewModel.Type); #endregion var property = new Property { ManagerId = User.Identity.GetUserId(), DateTime = viewModel.GetDateTime(), StatusId = viewModel.Status, TypeId = viewModel.Type, PropertyName = viewModel.PropertyName, Year = viewModel.Year, Description = viewModel.Description, Rooms = viewModel.Rooms, Bathrooms = viewModel.Bathrooms, Size = viewModel.Size, Price = viewModel.Price //Need to add Address }; _context.Properties.Add(property); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
// GET: Admin/Property/Create public ActionResult Create(int?id) { if (id == 0 || id == null) { TempData.Add("flash", new FlashDangerViewModel("A valid property listing type was not selected")); return(RedirectToAction("ListType", "Property", null)); } if (!Enum.IsDefined(typeof(PropertyListType), id)) { TempData.Add("flash", new FlashDangerViewModel("A valid property listing type was not selected")); return(RedirectToAction("ListType", "Property", null)); } var createProperty = new PropertyFormViewModel(); string userName = HttpContext.User.Identity.Name; var user = UserManager.FindByName(userName); createProperty.CompanyId = user.CompanyId; createProperty.PropertyListType = (PropertyListType)id; createProperty.PropertyTypeList = new List <SelectListItem>(); IEnumerable <PropertyType> propertyType = propertyTypeService.GetPropertyTypes(); createProperty.PropertyTypeList = from pt in propertyType select new SelectListItem { Text = pt.Name.ToString(), Value = pt.Id.ToString() }; ViewBag.PropertyListType = (PropertyListType)id; return(View(createProperty)); }
public async Task <IActionResult> Edit(int id, PropertyFormViewModel model) { bool IsPropertyExist = await this.propertyServce.ExistAsync(id); if (!IsPropertyExist) { ModelState.AddModelError(nameof(id), "Invalid Song"); } bool isRoomTypeExist = this.propertyServce.IsRoomTypeExists((int)model.RoomType); if (!isRoomTypeExist) { ModelState.AddModelError(nameof(model.RoomType), "Please select valid RoomType"); } bool isCityExist = await this.locationService.ExistAsync(model.CityId); if (!isCityExist) { ModelState.AddModelError(nameof(model.CityId), "Please select a valid City"); } bool isCityContainsSection = await this.locationService.ContainsSectionAsync(model.CityId, model.LocationId); if (!isCityContainsSection) { ModelState.AddModelError(nameof(model.LocationId), "That Location is not part of the selected city"); } if (!ModelState.IsValid) { return(View(new PropertyFormViewModel { Cities = await this.GetCitiesAsync(), Locations = await this.GetLocationsAsyncByCityId(model.CityId) })); } bool success = await this.propertyServce .EditAsync(id, model.Title, model.Description, model.Price, model.Space, model.RoomType, model.IsForRent, model.CityId, model.LocationId, model.HomeImage, model.HomeSecondaryImage); if (!success) { TempData.AddErrorMessage("Invalid Request"); } else { TempData.AddSuccessMessage($" Home {model.Title} has been edited successfully"); } return(RedirectToAction(nameof(ListAll))); }
public ActionResult Add() { PropertyFormViewModel model = this.propertyService.GeneratePropertyViewModel(); return(this.View(model)); }