public async Task <IActionResult> EditProperty(PropertyManagerViewModel viewModel) { if (ModelState.IsValid) { var propertyManager = await _converterHelper.ToPropertyManagerAsync(viewModel, false); _dataContext.PropertyManagers.Update(propertyManager); await _dataContext.SaveChangesAsync(); return(RedirectToAction("Details", "Managers", new { id = viewModel.ManagerId })); } return(View(viewModel)); }
public async Task <IActionResult> AddProperty(PropertyManagerViewModel viewModel) { if (ModelState.IsValid) { var propertyManager = await _converterHelper.ToPropertyManagerAsync(viewModel, true); _dataContext.PropertyManagers.Add(propertyManager); await _dataContext.SaveChangesAsync(); return(RedirectToAction("Details", "Managers", new { id = viewModel.ManagerId })); } viewModel.PropertyTypes = _combosHelper.GetComboPropertyTypes(); return(View(viewModel)); }
public async Task <PropertyManager> ToPropertyManagerAsync(PropertyManagerViewModel viewModel, bool isNew) { return(new PropertyManager { Id = isNew ? 0 : viewModel.ManagerId, Serie = viewModel.Serie, Company = viewModel.Company, Model = viewModel.Model, Colour = viewModel.Colour, IsAvailable = viewModel.IsAvailable, Price = viewModel.Price, Manager = await _dataContext.Managers.FindAsync(viewModel.ManagerId), PropertyType = await _dataContext.PropertyTypes.FindAsync(viewModel.PropertyTypeId), PropertyManagerImages = isNew ? new List <PropertyManagerImage>() : viewModel.PropertyManagerImages, Remarks = viewModel.Remarks }); }
public async Task <IActionResult> AddProperty(int?id) { if (id == null) { return(NotFound()); } var manager = await _dataContext.Managers.FindAsync(id); if (manager == null) { return(NotFound()); } var model = new PropertyManagerViewModel { ManagerId = manager.Id, PropertyTypes = _combosHelper.GetComboPropertyTypes() }; return(View(model)); }