aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-12-22 12:34:49 +0200
committerAvi Levkovich <avi@twine-s.com>2019-12-22 12:34:49 +0200
commit4f1b171aae508c983b1dffe8d21e40ba3b69c906 (patch)
treefae19719cb31ef70bfcf2d1fd4405ee35dd54a9b /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites
parent82f97b7000677ead42a6d075793c146fd7c8cf1d (diff)
parent1ee3c5e5cdacd6797fbcb87a7784b40fe5d6be7f (diff)
downloadTango-4f1b171aae508c983b1dffe8d21e40ba3b69c906.tar.gz
Tango-4f1b171aae508c983b1dffe8d21e40ba3b69c906.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs66
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/Views/SiteDetailsView.xaml2
3 files changed, 53 insertions, 29 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 486c8b46f..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
@@ -5,10 +5,13 @@ using System.Linq;
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;
using Tango.MachineStudio.Common;
+using Tango.MachineStudio.Common.Authentication;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.Sites.Contracts;
using Tango.MachineStudio.Sites.Models;
@@ -19,6 +22,8 @@ namespace Tango.MachineStudio.Sites.ViewModels
{
private ObservablesContext _db;
private INotificationProvider _notification;
+ private IAuthenticationProvider _authentication;
+ private IActionLogManager _actionLogManager;
private ActionTimer _filter_timer;
private List<SiteModel> _sites;
@@ -57,9 +62,11 @@ namespace Tango.MachineStudio.Sites.ViewModels
public RelayCommand BackToSitesCommand { get; set; }
- public MainViewVM(INotificationProvider notificationProvider)
+ public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
_notification = notificationProvider;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
_filter_timer = new ActionTimer(TimeSpan.FromMilliseconds(500));
ManageSiteCommand = new RelayCommand(() => LoadSelectedSite(), () => SelectedSite != null);
@@ -82,6 +89,7 @@ namespace Tango.MachineStudio.Sites.ViewModels
var site = _db.Sites.SingleOrDefault(x => x.Guid == SelectedSite.Guid);
site.Delete(_db);
_db.SaveChanges();
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.SiteDeleted, _authentication.CurrentUser, site.Name, site, "Site deleted using Machine Studio.");
Sites.Remove(SelectedSite);
LoadSites();
});
@@ -110,7 +118,7 @@ namespace Tango.MachineStudio.Sites.ViewModels
IsFree = false;
SiteDetailsViewVM = new SiteDetailsViewVM();
SiteDetailsViewVM.Saved += SiteDetailsViewVM_Saved;
- await SiteDetailsViewVM.Init(SelectedSite?.Guid, _notification, true, name);
+ await SiteDetailsViewVM.Init(SelectedSite?.Guid, _notification, _authentication, _actionLogManager, true, name);
View.NavigateTo(SitesNavigationView.SiteDetailsView);
}
}
@@ -134,7 +142,7 @@ namespace Tango.MachineStudio.Sites.ViewModels
IsFree = false;
SiteDetailsViewVM = new SiteDetailsViewVM();
SiteDetailsViewVM.Saved += SiteDetailsViewVM_Saved;
- await SiteDetailsViewVM.Init(SelectedSite.Guid, _notification, false);
+ await SiteDetailsViewVM.Init(SelectedSite.Guid, _notification, _authentication, _actionLogManager, false);
View.NavigateTo(SitesNavigationView.SiteDetailsView);
}
}
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 0e4dcbb47..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
@@ -10,6 +10,10 @@ using Tango.SharedUI;
using Tango.SharedUI.Components;
using System.Data.Entity;
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
{
@@ -17,6 +21,10 @@ namespace Tango.MachineStudio.Sites.ViewModels
{
private ObservablesContext _db;
private INotificationProvider _notification;
+ private IAuthenticationProvider _authentication;
+ private IActionLogManager _actionLogManager;
+ private bool _isNew;
+ private SiteDTO _siteBeforeSave;
public event EventHandler Saved;
@@ -34,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
{
@@ -69,9 +70,11 @@ namespace Tango.MachineStudio.Sites.ViewModels
SaveCommand = new RelayCommand(Save, () => IsFree);
}
- public async Task Init(String siteGuid, INotificationProvider notification, bool isNew, string newSiteName = null)
+ public async Task Init(String siteGuid, INotificationProvider notification, IAuthenticationProvider authentication, IActionLogManager actionLogManager, bool isNew, string newSiteName = null)
{
_notification = notification;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
_db = ObservablesContext.CreateDefault();
Organizations = await _db.Organizations.ToListAsync();
@@ -82,32 +85,36 @@ namespace Tango.MachineStudio.Sites.ViewModels
Site.Name = newSiteName;
Site.Description = "My site description";
_db.Sites.Add(Site);
+
+ _isNew = true;
}
else
{
- Site = await _db.Sites.SingleOrDefaultAsync(x => x.Guid == siteGuid);
+ _isNew = false;
+ 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());
+ 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());
- SelectedOrganization = Organizations.SingleOrDefault(x => x.Guid == Site.OrganizationGuid);
+ _siteBeforeSave = SiteDTO.FromObservable(Site);
}
private async void Save()
{
try
{
- Site.OrganizationGuid = SelectedOrganization?.Guid;
-
if (!Site.Validate(_db))
{
_notification.ShowError(String.Join("\n", Site.ValidationErrors));
@@ -118,23 +125,32 @@ 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();
+ //Remove site rmls.
+ 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));
- _db.SitesRmls.RemoveRange(site_rmls);
- _db.SitesCatalogs.RemoveRange(site_catalogs);
-
- foreach (var selectedRml in Rmls.SynchedSource)
+ 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)
+ 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();
+
+ if (_isNew)
+ {
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.SiteCreated, _authentication.CurrentUser, Site.Name, Site, "Site created using Machine Studio.");
+ }
+ else
+ {
+ SiteDTO siteAfter = SiteDTO.FromObservable(Site);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.SiteSaved, _authentication.CurrentUser, _siteBeforeSave.Name, _siteBeforeSave, siteAfter, "Site saved using Machine Studio.");
+ _siteBeforeSave = siteAfter;
+ }
}
_db.Dispose();
Saved?.Invoke(this, new EventArgs());
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>