public async Task <IActionResult> EditProperty(PropertySupervisorViewModel viewModel) { if (ModelState.IsValid) { var propertySupervisor = await _converterHelper.ToPropertySupervisorAsync(viewModel, false); _dataContext.PropertySupervisors.Update(propertySupervisor); await _dataContext.SaveChangesAsync(); return(RedirectToAction("Details", "Supervisors", new { id = viewModel.SupervisorId })); } return(View(viewModel)); }
public async Task <IActionResult> AddProperty(PropertySupervisorViewModel viewModel) { if (ModelState.IsValid) { var propertySupervisor = await _converterHelper.ToPropertySupervisorAsync(viewModel, true); _dataContext.PropertySupervisors.Add(propertySupervisor); await _dataContext.SaveChangesAsync(); return(RedirectToAction("Details", "Supervisors", new { id = viewModel.SupervisorId })); } viewModel.PropertyTypes = _combosHelper.GetComboPropertyTypes(); return(View(viewModel)); }
public async Task <PropertySupervisor> ToPropertySupervisorAsync(PropertySupervisorViewModel viewModel, bool isNew) { return(new PropertySupervisor { Id = isNew ? 0 : viewModel.SupervisorId, Serie = viewModel.Serie, Company = viewModel.Company, Model = viewModel.Model, Colour = viewModel.Colour, IsAvailable = viewModel.IsAvailable, Price = viewModel.Price, Supervisor = await _dataContext.Supervisors.FindAsync(viewModel.SupervisorId), PropertyType = await _dataContext.PropertyTypes.FindAsync(viewModel.PropertyTypeId), PropertySupervisorImages = isNew ? new List <PropertySupervisorImage>() : viewModel.PropertySupervisorImages, Remarks = viewModel.Remarks }); }
public async Task <IActionResult> AddProperty(int?id) { if (id == null) { return(NotFound()); } var supervisor = await _dataContext.Supervisors.FindAsync(id); if (supervisor == null) { return(NotFound()); } var model = new PropertySupervisorViewModel { SupervisorId = supervisor.Id, PropertyTypes = _combosHelper.GetComboPropertyTypes() }; return(View(model)); }