diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-21 22:39:08 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-21 22:39:08 +0200 |
| commit | aeb55d27a8abf291913724fc1676ecbf27cb2c1a (patch) | |
| tree | 007b0287c23b75883750a786cb2601afbf7f5d81 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites | |
| parent | 582c05b00aa1d0fd9086b4a245dcc987eee9fc39 (diff) | |
| download | Tango-aeb55d27a8abf291913724fc1676ecbf27cb2c1a.tar.gz Tango-aeb55d27a8abf291913724fc1676ecbf27cb2c1a.zip | |
Refactored Site Rmls & Catalogs to FK.
Implemented Sites & Site Builders.
Implemented DTO's and ActionLogs.
Changed SQLExaminer scripts accordingly.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites')
3 files changed, 19 insertions, 34 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs index bcbcb6d16..5db5e004d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.BL.ActionLogs; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.Threading; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs index 73d4c49cb..92dd8273d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs @@ -13,6 +13,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.Authentication; using Tango.BL.ActionLogs; using Tango.BL.DTO; +using Tango.BL.Builders; namespace Tango.MachineStudio.Sites.ViewModels { @@ -41,13 +42,6 @@ namespace Tango.MachineStudio.Sites.ViewModels set { _organizations = value; RaisePropertyChangedAuto(); } } - private Organization _selectedOrganization; - public Organization SelectedOrganization - { - get { return _selectedOrganization; } - set { _selectedOrganization = value; RaisePropertyChangedAuto(); } - } - private SelectedObjectCollection<Rml> _rmls; public SelectedObjectCollection<Rml> Rmls { @@ -97,31 +91,30 @@ namespace Tango.MachineStudio.Sites.ViewModels else { _isNew = false; - Site = await _db.Sites.SingleOrDefaultAsync(x => x.Guid == siteGuid); + Site = await new SiteBuilder(_db).Set(siteGuid) + .WithSiteCatalogs() + .WithCatalogs() + .WithSiteRmls() + .WithRmls() + .WithOrganization() + .BuildAsync(); } Machines = await _db.Machines.Where(x => x.SiteGuid == Site.Guid).Include(x => x.Organization).ToListAsync(); - var site_rmls = await _db.SitesRmls.Where(x => x.SiteGuid == Site.Guid).ToListAsync(); - var site_catalogs = await _db.SitesCatalogs.Where(x => x.SiteGuid == Site.Guid).ToListAsync(); - var rmls = await _db.Rmls.OrderBy(x => x.Name).ToListAsync(); var catalogs = await _db.ColorCatalogs.OrderBy(x => x.Name).ToListAsync(); - Rmls = new SelectedObjectCollection<Rml>(rmls.ToObservableCollection(), rmls.Where(rml => site_rmls.Exists(siteRml => siteRml.RmlGuid == rml.Guid)).ToObservableCollection()); - Catalogs = new SelectedObjectCollection<ColorCatalog>(catalogs.ToObservableCollection(), catalogs.Where(catalog => site_catalogs.Exists(siteCatalog => siteCatalog.CatalogGuid == catalog.Guid)).ToObservableCollection()); - - SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == Site.OrganizationGuid); + Rmls = new SelectedObjectCollection<Rml>(rmls.ToObservableCollection(), Site.SitesRmls.Select(x => x.Rml).ToObservableCollection()); + Catalogs = new SelectedObjectCollection<ColorCatalog>(catalogs.ToObservableCollection(), Site.SitesCatalogs.Select(x => x.ColorCatalog).ToObservableCollection()); - _siteBeforeSave = SiteDTO.FromObservable(Site, site_rmls, site_catalogs, SelectedOrganization.Name); + _siteBeforeSave = SiteDTO.FromObservable(Site); } private async void Save() { try { - Site.OrganizationGuid = SelectedOrganization?.Guid; - if (!Site.Validate(_db)) { _notification.ShowError(String.Join("\n", Site.ValidationErrors)); @@ -132,38 +125,29 @@ namespace Tango.MachineStudio.Sites.ViewModels using (_notification.PushTaskItem("Saving site details...")) { - var site_rmls = await _db.SitesRmls.Where(x => x.SiteGuid == Site.Guid).ToListAsync(); - var site_catalogs = await _db.SitesCatalogs.Where(x => x.SiteGuid == Site.Guid).ToListAsync(); - - //_db.SitesRmls.RemoveRange(site_rmls); - //_db.SitesCatalogs.RemoveRange(site_catalogs); - //Remove site rmls. - site_rmls.ToList().Where(x => !Rmls.SynchedSource.ToList().Exists(y => y.Guid == x.RmlGuid)).ToList().ForEach(x => _db.SitesRmls.Remove(x)); - site_catalogs.ToList().Where(x => !Catalogs.SynchedSource.ToList().Exists(y => y.Guid == x.CatalogGuid)).ToList().ForEach(x => _db.SitesCatalogs.Remove(x)); + Site.SitesRmls.ToList().Where(x => !Rmls.SynchedSource.ToList().Exists(y => y.Guid == x.RmlGuid)).ToList().ForEach(x => _db.SitesRmls.Remove(x)); + Site.SitesCatalogs.ToList().Where(x => !Catalogs.SynchedSource.ToList().Exists(y => y.Guid == x.ColorCatalogGuid)).ToList().ForEach(x => _db.SitesCatalogs.Remove(x)); - foreach (var selectedRml in Rmls.SynchedSource.Where(x => !site_rmls.Exists(y => y.RmlGuid == x.Guid))) + foreach (var selectedRml in Rmls.SynchedSource.Where(x => !Site.SitesRmls.ToList().Exists(y => y.RmlGuid == x.Guid))) { _db.SitesRmls.Add(new SitesRml() { SiteGuid = Site.Guid, RmlGuid = selectedRml.Guid }); } - foreach (var selectedCatalog in Catalogs.SynchedSource.Where(x => !site_catalogs.Exists(y => y.CatalogGuid == x.Guid))) + foreach (var selectedCatalog in Catalogs.SynchedSource.Where(x => !Site.SitesCatalogs.ToList().Exists(y => y.ColorCatalogGuid == x.Guid))) { - _db.SitesCatalogs.Add(new SitesCatalog() { SiteGuid = Site.Guid, CatalogGuid = selectedCatalog.Guid }); + _db.SitesCatalogs.Add(new SitesCatalog() { SiteGuid = Site.Guid, ColorCatalogGuid = selectedCatalog.Guid }); } await _db.SaveChangesAsync(); - var final_site_rmls = _db.SitesRmls.ToList(); - var final_site_catalogs = _db.SitesCatalogs.ToList(); - if (_isNew) { _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.SiteCreated, _authentication.CurrentUser, Site.Name, Site, "Site created using Machine Studio."); } else { - SiteDTO siteAfter = SiteDTO.FromObservable(Site, final_site_rmls, final_site_catalogs, SelectedOrganization.Name); + SiteDTO siteAfter = SiteDTO.FromObservable(Site); _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.SiteSaved, _authentication.CurrentUser, _siteBeforeSave.Name, _siteBeforeSave, siteAfter, "Site saved using Machine Studio."); _siteBeforeSave = siteAfter; } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/Views/SiteDetailsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/Views/SiteDetailsView.xaml index b3496a5e2..182f05be0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/Views/SiteDetailsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/Views/SiteDetailsView.xaml @@ -84,7 +84,7 @@ <TextBox Text="{Binding Site.Name,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}"></TextBox> <TextBlock Text="Organization:" ></TextBlock> - <ComboBox ItemsSource="{Binding Organizations}" SelectedItem="{Binding SelectedOrganization}" DisplayMemberPath="Name"></ComboBox> + <ComboBox ItemsSource="{Binding Organizations}" SelectedItem="{Binding Site.Organization}" DisplayMemberPath="Name"></ComboBox> <TextBlock Text="Description:" ></TextBlock> <TextBox Text="{Binding Site.Description,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True,ValidatesOnNotifyDataErrors=True}"></TextBox> |
