public ActionResult Delete(TenantFormViewModel viewModel) { if (!ViewData.ModelState.IsValid) { return this.RedirectToAction(c => c.Edit(viewModel.Id)); } try { var tenant = _tenantRepository.Get(viewModel.Id); _tenantRepository.Delete(tenant); TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully deleted tenant '{0}'", tenant.Name); } catch (Exception ex) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred deleting the tenant: {0}", ex.Message); return this.RedirectToAction(c => c.Edit(viewModel.Id)); } return this.RedirectToAction(c => c.Index(null)); }
public ActionResult Create(TenantFormViewModel viewModel) { if (!ViewData.ModelState.IsValid) { TempData.SafeAdd(viewModel); return this.RedirectToAction(c => c.Create()); } try { var tenant = new Tenant { Name = viewModel.Name, Domain = viewModel.Domain, ConnectionString = viewModel.ConnectionString}; _tenantRepository.SaveOrUpdate(tenant); TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully created tenant '{0}'", tenant.Name); } catch (Exception ex) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred creating the tenant: {0}", ex.Message); return this.RedirectToAction(c => c.Create()); } return this.RedirectToAction(c => c.Index(null)); }
public ActionResult Delete(int id) { var tenant = _tenantRepository.Get(id); var viewModel = new TenantFormViewModel(tenant); return View(viewModel); }