public async Task <Building> DeleteBuildingById(int id) { var bldg = await _buildingsRepo.GetFirstOrDefault(b => b.Id == id); await _buildingsRepo.Delete(bldg.Id); await _buildingsRepo.SaveAsync(); return(bldg); }
public ActionResult DeleteBuilding(int buildingId) { try { int i = repo.Delete(buildingId); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message.ToString() }, JsonRequestBehavior.AllowGet)); } }
public IActionResult Remove(Building model) { var result = _buildingRepository.Delete(model.BuildingID); if (result.Success) { return(RedirectToAction("List")); } else { throw new Exception(result.Messages[0]); } }
public ActionResult Delete(int id) { Building item = repository.Get(id); if (User.Identity.GetUserId() == item.UserId) { repository.Delete(item); uow.Save(); DeleteFiles(item.Photos); return(RedirectToAction("Browse", "Buildings")); } return(RedirectToAction("Login", "Account")); }
public IActionResult DeleteBuilding(int id) { if (!_buildingRepository.Get(id).Success) { return(NotFound($"Building {id} not found")); } var result = _buildingRepository.Delete(id); if (result.Success) { return(Ok()); } else { return(BadRequest(result.Messages)); } }
public MainViewModel(IClientRepository clientsRepo, IBuildingRepository buildingRepo, IContractRepository contractRepo) { // передача значений полю от переданного объекта клиенты this.clientsRepo = clientsRepo; this.buildingRepo = buildingRepo; this.contractRepo = contractRepo; // заполенение свойства элементами дерева из БД ListClient = new ObservableCollection <Client>(this.clientsRepo.GetAll()); DayOfTheWeek = DateTime.Now.DayOfWeek.ToString(); DispatcherTimer t = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 50), DispatcherPriority.Background, t_Tick, Dispatcher.CurrentDispatcher); t.IsEnabled = true; //установка выбранного объекта дерева в свойство SetSelectedItemCommand = new RelayCommand <object>(item => { if (item is Client) { SelectedClient = item as Client; SelectedBuilding = null; SelectedContract = null; SelectedName = SelectedClient.Organization; DynamicUserControl = new UserControlClients(SelectedClient); ChartsUserControl = new UserControlDiagram(); SelectedObject = 1; ParentClient = null; ParentContract = null; } else if (item is Contract) { SelectedContract = item as Contract; SelectedClient = null; SelectedBuilding = null; SelectedName = SelectedContract.ContractNumber; DynamicUserControl = new UserControlContracts(SelectedContract); ChartsUserControl = new UserControlDiagram(SelectedContract); SelectedObject = 2; ParentClient = ListClient.First(clnt => clnt.ClientID == SelectedContract.ClientID); ParentContract = null; } else if (item is Building) { SelectedBuilding = item as Building; SelectedContract = null; SelectedClient = null; SelectedName = SelectedBuilding.NameOfTheObject; DynamicUserControl = new UserControlBuildings(SelectedBuilding); ChartsUserControl = new UserControlDiagram(); SelectedObject = 3; ParentContract = contractRepo.GetContractById(SelectedBuilding); //получили родительский контракт из БД ParentClient = ListClient.First(client => client.ClientID == ParentContract.ClientID); //получили родительского клиента из ListClient ParentContract = ParentClient.Contract.First(ctr => ctr.ContractNumber == ParentContract.ContractNumber); //переписали контракт на контракт из ListClient } }); #region commands // удалить объект Action DeleteBuildingAction = () => { Building bld = SelectedBuilding; buildingRepo.Delete(bld); ParentContract.Building.Remove(bld); }; actions.Add(DeleteBuildingAction); DeleteBuildingCmd = new RelayCommand(DeleteBuildingAction, () => SelectedObject == 3); // редактировать объект UpdateBuildingCmd = new RelayCommand(() => { if (SelectedBuilding != null) { BuildingDialog buildDlg = new BuildingDialog(SelectedBuilding); if (buildDlg.ShowDialog() == true) { buildingRepo.Update(buildDlg.NewBuilding); SelectedBuilding = buildDlg.NewBuilding; } } }, () => SelectedObject == 3); // добавить объект AddBuildingCmd = new RelayCommand(() => { Building bld; BuildingDialog buildDlg = new BuildingDialog(SelectedContract); if (buildDlg.ShowDialog() == true) { bld = buildDlg.NewBuilding; buildingRepo.Add(ref bld); if (SelectedContract.Building == null) { SelectedContract.Building = new ObservableCollection <Building>(); } SelectedContract.Building.Add(bld); } }, () => SelectedObject == 2); // редактировать клиента UpdateClientCmd = new RelayCommand(() => { Client clt; ClientDialog clntDlg = new ClientDialog(SelectedClient); if (clntDlg.ShowDialog() == true) { clt = clntDlg.NewClient; clientsRepo.Update(clntDlg.NewClient); } }, () => SelectedObject == 1); // добавить клиента AddClientCmd = new RelayCommand(() => { Client clt; ClientDialog clntDlg = new ClientDialog(); if (clntDlg.ShowDialog() == true) { clt = clntDlg.NewClient; clientsRepo.Add(ref clt); ListClient.Add(clt); } }, () => SelectedObject == 1); // добавить контракт AddContractCmd = new RelayCommand(() => { Contract contract; ContractDialog contractDialog = new ContractDialog(SelectedClient); if (contractDialog.ShowDialog() == true) { contract = contractDialog.NewContract; contract.ClientID = SelectedClient.ClientID; contractRepo.Add(ref contract); if (SelectedClient.Contract == null) { SelectedClient.Contract = new ObservableCollection <Contract>(); } SelectedClient.Contract.Add(contract); } }, () => SelectedObject == 1); // редактировать контракт UpdateContractCmd = new RelayCommand(() => { Contract contract; ContractDialog contractDialog = new ContractDialog(SelectedContract); if (contractDialog.ShowDialog() == true) { contract = contractDialog.NewContract; contractRepo.Update(contractDialog.NewContract); } }, () => SelectedObject == 2); // удалить контракт DeleteContractCmd = new RelayCommand(() => { Contract contract = SelectedContract; contractRepo.Delete(SelectedContract); if (SelectedContract.Building != null) { SelectedContract.Building.Clear(); } ParentClient.Contract.Remove(SelectedContract); }, () => SelectedObject == 2); // удалить клиента DeleteClientCmd = new RelayCommand(() => { Client contract = SelectedClient; clientsRepo.Delete(SelectedClient); if (SelectedClient.Contract != null) { SelectedClient.Contract.Clear(); } ListClient.Remove(SelectedClient); }, () => SelectedObject == 1); // вывести сметы в XML BuildingToXmlCmd = new RelayCommand(() => { XDocument BuildingsXML = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Lizzard #smiles #loveMVVM #IAmGoodStudent"), new XElement("Buildings", buildingRepo.GetAll().Select(bld => new XElement("Building", new XAttribute("ID", bld.ObjectID), new XElement("Name", bld.NameOfTheObject), new XElement("Contract_Number", bld.ContractNumber), new XElement("Issue_Date", bld.IssueDate.ToLongDateString()), new XElement("Cost", bld.CostOfTheObject) ) ) )); BuildingsXML.Save(@"Buildings.xml"); }); #endregion }
/// <inheritdoc cref="IDeletable.Delete(long[])"/> public void Delete(params long[] ids) { _repository.Delete(ids); }
public bool Delete(int id) { return(buildingRepository.Delete(id)); }
public bool Delete(Building building) { return(_buildingRepository.Delete(building)); }
public void Delete(int id) { _buildingRepository.Delete(id); }