public void InsertBuilding(BuildingDto b) { try { //check if exist building with the same name var exist = _buildingRepository.GetAll().Any(x => x.Name.ToLower() == b.Name.ToLower()); if (!exist) { var newB = new Building() { Name = b.Name, Address = b.Address, City = b.City, IsAvailable = b.IsAvailable, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; _buildingRepository.Add(newB); LogManager.Debug($"Inserito nuovo edificio (Nome:{newB.Name}, Indirizzo:{newB.Address}, Citta':{newB.City})"); } else { throw new Exception($"E' già presente un edificio con nome '{b.Name}'"); } } catch (Exception ex) { LogManager.Error(ex); throw ex; } }
public async Task GetAll_ShouldReturnAllBuildings_WhenThereAreAllParametersPassed() { // Arrange var buildingsData = SeedBuildings(); _buildingRepository.GetAll().Returns(buildingsData); var city = "warszawa"; var street = "afrodyty"; var startSN = 2; var endSN = 7; var even = false; var buildingsWithFilters = buildingsData.Count(a => string.Equals(a.City, city, StringComparison.OrdinalIgnoreCase) && string.Equals(a.Street, street, StringComparison.OrdinalIgnoreCase) && a.StreetNumber >= startSN && a.StreetNumber <= endSN && a.StreetNumber % 2 == 0 == even); // Act var buildings = _sut.GetAll(city, street, startSN, endSN, even).ToList(); // Assert buildings.Should().NotBeNull(); buildings.Should().HaveCount(buildingsWithFilters); buildings.Should().Match(b => b.All(a => string.Equals(a.City, city, StringComparison.OrdinalIgnoreCase))); buildings.Should().Match(b => b.All(a => string.Equals(a.Street, street, StringComparison.OrdinalIgnoreCase))); buildings.Should().Match(b => b.All(a => a.StreetNumber >= startSN)); buildings.Should().Match(b => b.All(a => a.StreetNumber <= endSN)); buildings.Should().Match(b => b.All(a => a.StreetNumber % 2 == 0 == even)); }
public IEnumerable <Building> GetAll(string city = null, string street = null, int?streetNumberStart = null, int?streetNumberEnd = null, bool?even = null) { var result = _repository.GetAll(); if (city != null) { result = result.Where(b => string.Equals(b.City, city, StringComparison.CurrentCultureIgnoreCase)); } if (street != null) { result = result.Where(b => string.Equals(b.Street, street, StringComparison.CurrentCultureIgnoreCase)); } if (streetNumberStart.HasValue) { result = result.Where(b => b.StreetNumber >= streetNumberStart); } if (streetNumberEnd.HasValue) { result = result.Where(b => b.StreetNumber <= streetNumberEnd); } if (even.HasValue) { result = result.Where(b => b.StreetNumber % 2 == 0 == even); } return(result.OrderBy(b => b.StreetNumber)); }
public ActionResult Index() { var buildings = _buildingRepository.GetAll(CurrentOrganization.Id).ToDictionary(_ => _.Id, _ => _.Name); ViewBag.Floors = _floorRepository.GetAllByOrganization(CurrentOrganization.Id) .ToDictionary(_ => _.Id, _ => string.Format("{0} - {1}", buildings.TryGetValue(_.BuildingId), _.Name)); return(View(_roomRepository.GetRoomInfosForOrganization(CurrentOrganization.Id))); }
public ActionResult Index() { var buildings = _buildingRepository.GetAll(CurrentOrganization.Id).ToDictionary(_ => _.Id, _ => _.Name); ViewBag.Buildings = buildings; var floors = _floorRepository.GetAllByOrganization(CurrentOrganization.Id).ToDictionary(_ => _.Id, _ => _.Name); ViewBag.Rooms = _roomMetadataRepository.GetRoomInfosForOrganization(CurrentOrganization.Id) .ToDictionary(_ => _.Id, _ => string.Format("{0} - {1} - {2}", buildings.TryGetValue(_.BuildingId), floors.TryGetValue(_.FloorId), _.RoomAddress)); return(View(_deviceRepository.GetForOrganization(CurrentOrganization.Id))); }
public IActionResult Get() { try { IEnumerable <Building> buildinglist = _buildingRepository.GetAll(); return(Ok(buildinglist)); } catch { return(new NoContentResult()); } }
public IActionResult List() { var result = _buildingRepository.GetAll(); if (result.Success) { return(View(result.Data)); } else { throw new Exception(result.Messages[0]); } }
public IActionResult Get() { try { _log4net.Info(" Http GET is accesed"); IEnumerable <Building> buildinglist = _buildingRepository.GetAll(); _log4net.Info("list is retrieved"); return(Ok(buildinglist)); } catch { _log4net.Error("Error in Get request"); return(new NoContentResult()); } }
public IActionResult GetBuildings() { var result = _buildingRepository.GetAll(); if (result.Success) { return(Ok( result.Data.Select( b => new { b.BuildingID, b.BuildingName }) )); } else { throw new Exception(result.Messages[0]); } }
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 }
public IEnumerable <Building> GetAll() { return(buildingRepository.GetAll()); }
public JsonResult Buildings() { var buildings = _buildingRepository.GetAll(CurrentOrganization.Id); return(Json(buildings.Select(_ => new { id = _.Id, text = _.Name }).OrderBy(_ => _.text), JsonRequestBehavior.AllowGet)); }
public ViewResult Browse(int index = 1) { return(View(ToTableModels(repository.GetAll()).ToPagedList(PAGE_SIZE, index))); }
public ActionResult Index() { ViewBag.Buildings = _buildingRepository.GetAll(CurrentOrganization.Id).ToDictionary(_ => _.Id, _ => _.Name); return(View(_floorRepository.GetAllByOrganization(CurrentOrganization.Id))); }
public ActionResult Index() { return(View(_buildingRepository.GetAll(CurrentOrganization.Id))); }