aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-21 19:14:00 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-21 19:14:00 +0200
commit582c05b00aa1d0fd9086b4a245dcc987eee9fc39 (patch)
tree7b26e3b9b182a921ff9f69db63bc5f6972c205de /Software/Visual_Studio/MachineStudio/Modules
parent76cdf188e28544cd5056c30f35d77590d9a79cae (diff)
downloadTango-582c05b00aa1d0fd9086b4a245dcc987eee9fc39.tar.gz
Tango-582c05b00aa1d0fd9086b4a245dcc987eee9fc39.zip
Working some more on ActionLogs across MS.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs4
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs10
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs6
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs32
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs28
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/MainViewVM.cs13
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Sites/ViewModels/SiteDetailsViewVM.cs42
7 files changed, 114 insertions, 21 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs
index ae763167b..e306d0997 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Catalogs/ViewModels/MainViewVM.cs
@@ -244,7 +244,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels
{
IsFree = false;
await SelectedCatalog.DeleteCascadeAsync(_catalogsContext);
- _actionLogManager.InsertLog(ActionLogType.CatalogDeleted, _authentication.CurrentUser, SelectedCatalog.Name, SelectedCatalog, "Catalog deleted using Machine Studio.");
+ _actionLogManager.InsertLog(ActionLogType.CatalogDeleted, _authentication.CurrentUser, SelectedCatalog.Name, SelectedCatalog, "Catalog deleted using Machine Studio.", false);
SelectedCatalog = null;
}
catch (Exception ex)
@@ -322,7 +322,7 @@ namespace Tango.MachineStudio.Catalogs.ViewModels
await _activeCatalogContext.SaveChangesAsync();
var activeCatalogDTO = ColorCatalogDTO.FromObservable(ActiveCatalog);
- _actionLogManager.InsertLog(ActionLogType.CatalogSaved, _authentication.CurrentUser, ActiveCatalog.Name, _catalogBeforeSave, activeCatalogDTO, "Catalog created using Machine Studio.");
+ _actionLogManager.InsertLog(ActionLogType.CatalogSaved, _authentication.CurrentUser, _catalogBeforeSave.Name, _catalogBeforeSave, activeCatalogDTO, "Catalog created using Machine Studio.");
_catalogBeforeSave = activeCatalogDTO;
await LoadCatalogs();
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
index 8b235a13a..a641c87b6 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
@@ -1726,6 +1726,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
using (_notification.PushTaskItem("Saving Parameters Group..."))
{
+ var processGroupBefore = ProcessParametersTablesGroupDTO.FromObservable(SelectedRML.GetActiveProcessGroup());
+
using (var db = ObservablesContext.CreateDefault())
{
var active_groups = db.ProcessParametersTablesGroups.Where(x => x.RmlGuid == SelectedRML.Guid && x.Active).ToList();
@@ -1753,8 +1755,6 @@ namespace Tango.MachineStudio.Developer.ViewModels
tables.Add(newTable);
}
- var rmlBeforeDTO = RmlDTO.FromObservable(SelectedRML);
-
group.Active = true;
group.ProcessParametersTables = tables.ToSynchronizedObservableCollection();
group.Rml = SelectedRML;
@@ -1769,7 +1769,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
SelectedRML.ProcessParametersTablesGroups.Add(group);
await SelectedRML.SaveAsync(_activeJobDbContext);
- _actionLogManager.InsertLog(ActionLogType.RmlSaved, AuthenticationProvider.CurrentUser, SelectedRML.Name, rmlBeforeDTO, RmlDTO.FromObservable(SelectedRML), "Active process parameters changed from Machine Studio Research module.");
+ _actionLogManager.InsertLog(ActionLogType.RmlActiveProcessParametersChanged, AuthenticationProvider.CurrentUser, SelectedRML.Name, processGroupBefore, ProcessParametersTablesGroupDTO.FromObservable(SelectedRML.GetActiveProcessGroup()), "RML Active process parameters changed from Machine Studio Research module.");
InvalidateLiquidFactorsAndProcessTables();
}
@@ -2421,7 +2421,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
foreach (var job in SelectedJobs)
{
- _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, job.Name, job, "Job created using Machine Studio.");
+ _actionLogManager.InsertLog(ActionLogType.JobCreated, AuthenticationProvider.CurrentUser, job.Name, job, "Job cloned using Machine Studio.");
}
CanWork = true;
@@ -2664,7 +2664,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
foreach (var job in jobsToReport)
{
- _actionLogManager.InsertLog(ActionLogType.JobImported, AuthenticationProvider.CurrentUser, job.Name, job, "New job imported using Machine Studio.");
+ _actionLogManager.InsertLog(ActionLogType.JobImported, AuthenticationProvider.CurrentUser, job.Name, job, "Job imported using Machine Studio.");
}
IsFree = true;
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
index 7c95ce270..0a8780346 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
@@ -193,6 +193,8 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db.HardwareVersions.Add(hv);
await _db.SaveChangesAsync();
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionImported, _authentication.CurrentUser, CurrentVersion.Name, CurrentVersion, "New hardware version imported using Machine Studio.");
+
RefreshVersions();
InvokeUI(() =>
@@ -436,7 +438,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db.SaveChanges();
var dtoAfter = HardwareVersionDTO.FromObservable(CurrentVersion);
- _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionSaved, _authentication.CurrentUser, CurrentVersion.Name, _hwBeforeSave, dtoAfter, "Hardware Version saved using Machine Studio.");
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionSaved, _authentication.CurrentUser, _hwBeforeSave.Name, _hwBeforeSave, dtoAfter, "Hardware Version saved using Machine Studio.");
_hwBeforeSave = dtoAfter;
RefreshVersions();
@@ -481,7 +483,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
_db.HardwareVersions.Add(cloned);
_db.SaveChanges();
- _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, cloned.Name, cloned, "New hardware version created (cloned) using Machine Studio.");
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.HardwareVersionCreated, _authentication.CurrentUser, cloned.Name, cloned, "New hardware version cloned using Machine Studio.");
RefreshVersions();
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
index fd31cd950..7b6ae7ef0 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs
@@ -25,14 +25,21 @@ using Tango.Core.Threading;
using Tango.MachineStudio.RML.ViewModels;
using Tango.Settings;
using Tango.MachineStudio.RML.Models;
+using Tango.BL.ActionLogs;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.DTO;
namespace Tango.MachineStudio.MachineDesigner.ViewModels
{
public class MainViewVM : StudioViewModel<IMainView>
{
private INotificationProvider _notification;
+ private IActionLogManager _actionLogManager;
+ private IAuthenticationProvider _authentication;
private ActionTimer _machines_action_timer;
private ActionTimer _dispensers_action_timer;
+ private MachineDTO _machineBeforeSave;
+ private bool _isNewMachine;
#region Properties
@@ -233,10 +240,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
/// <summary>
/// Initializes a new instance of the <see cref="MainViewVM"/> class.
/// </summary>
- public MainViewVM(INotificationProvider notification)
+ public MainViewVM(INotificationProvider notification, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
MachinesAdapter = new ObservablesStaticCollections(ObservablesContext.CreateDefault());
_notification = notification;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
_machines_action_timer = new ActionTimer(TimeSpan.FromMilliseconds(200));
_dispensers_action_timer = new ActionTimer(TimeSpan.FromMilliseconds(200));
@@ -428,6 +437,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
private async void LoadSelectedMachine(bool newMachine = false, bool clone = false, MachineVersion selectedVersion = null)
{
+ _isNewMachine = false;
+
using (_notification.PushTaskItem("Loading machine details..."))
{
try
@@ -462,9 +473,12 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
if (!newMachine)
{
ActiveMachine = (await new MachineBuilder(ActiveMachineAdapter.Context).Set(SelectedMachine.Guid).WithOrganization().WithConfiguration().WithSpools().BuildAsync());
+ _machineBeforeSave = MachineDTO.FromObservable(ActiveMachine);
+
if (clone)
{
+ _isNewMachine = true;
ActiveMachine = ActiveMachine.Clone();
ActiveMachine.Name = "";
ActiveMachine.SerialNumber = "";
@@ -476,6 +490,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
}
else
{
+ _isNewMachine = true;
+
if (selectedVersion == null)
{
ActiveMachine = new Machine();
@@ -668,16 +684,25 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
ActiveMachine.ConfigurationGuid = ActiveMachine.Configuration.Guid;
ActiveMachine.LastUpdated = DateTime.UtcNow;
- ActiveMachine.ProductionDate = DateTime.UtcNow;
ActiveMachine.SiteGuid = SelectedSite == null ? null : (SelectedSite.ID == -1 ? null : SelectedSite.Guid);
ColorCalibrationViewVM.Save();
var hwConfig = HardwareConfigurationViewVM.GetResultingHardwareConfiguration();
ActiveMachine.Configuration.SetHardwareConfiguration(hwConfig);
-
await ActiveMachineAdapter.Context.SaveChangesAsync();
+ if (_isNewMachine)
+ {
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineCreated, _authentication.CurrentUser, ActiveMachine.Name, ActiveMachine, "New machine created using Machine Studio.");
+ }
+ else
+ {
+ var machineAfterDTO = MachineDTO.FromObservable(ActiveMachine);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineSaved, _authentication.CurrentUser, _machineBeforeSave.Name, _machineBeforeSave, machineAfterDTO, "Machine saved using Machine Studio.");
+ _machineBeforeSave = machineAfterDTO;
+ }
+
if (SelectedMachine != null)
{
await SelectedMachine.Reload(MachinesAdapter.Context);
@@ -725,6 +750,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels
IsFree = false;
await SelectedMachine.DeleteCascadeAsync(MachinesAdapter.Context);
MachinesAdapter.Context.Machines.Remove(SelectedMachine);
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.MachineDeleted, _authentication.CurrentUser, SelectedMachine.Name, SelectedMachine, "Machine deleted using Machine Studio.");
}
catch (Exception ex)
{
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
index 9939e4876..527159aa5 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs
@@ -21,12 +21,18 @@ using Tango.MachineStudio.RML.Views;
using Tango.PMR.ColorLab;
using System.Data.Entity;
using Tango.Core.ExtensionMethods;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.BL.ActionLogs;
+using Tango.BL.DTO;
namespace Tango.MachineStudio.RML.ViewModels
{
public class MainViewVM : StudioViewModel<IMainView>
{
private INotificationProvider _notification;
+ private IAuthenticationProvider _authentication;
+ private IActionLogManager _actionLogManager;
+ private RmlDTO _rmlBeforeSave;
private ObservablesContext _rmls_context;
private ObservablesContext _active_context;
@@ -185,9 +191,11 @@ namespace Tango.MachineStudio.RML.ViewModels
public RelayCommand ImportRMLFileCommand { get; set; }
- public MainViewVM(INotificationProvider notificationProvider)
+ public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager)
{
_notification = notificationProvider;
+ _authentication = authentication;
+ _actionLogManager = actionLogManager;
ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null);
RemoveRmlCommand = new RelayCommand(RemoveSelectedRml, () => SelectedRML != null);
CloneRmlCommand = new RelayCommand(CloneSelectedRml, () => SelectedRML != null);
@@ -334,6 +342,8 @@ namespace Tango.MachineStudio.RML.ViewModels
LiquidTypesRmls = LiquidTypesRmls,
};
+ _rmlBeforeSave = RmlDTO.FromObservable(ActiveRML);
+
View.NavigateTo(RmlNavigationView.RmlView);
InvalidateRelayCommands();
@@ -423,6 +433,9 @@ namespace Tango.MachineStudio.RML.ViewModels
_active_context.ProcessParametersTables.Add(group.ProcessParametersTables[0]);
_active_context.Rmls.Add(rml);
await _active_context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, rml.Name, rml, "Rml created using Machine Studio.");
+
LoadActiveRML(rml.Guid);
IsFree = true;
@@ -441,6 +454,9 @@ namespace Tango.MachineStudio.RML.ViewModels
try
{
await SelectedRML.DeleteCascadeAsync(_rmls_context);
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlDeleted, _authentication.CurrentUser, SelectedRML.Name, SelectedRML, "RML deleted from Machine Studio.");
+
LoadRmls();
}
catch (Exception ex)
@@ -504,6 +520,8 @@ namespace Tango.MachineStudio.RML.ViewModels
context.Rmls.Add(cloned);
await context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlCreated, _authentication.CurrentUser, cloned.Name, cloned, "RML cloned from Machine Studio.");
}
LoadRmls();
@@ -665,7 +683,13 @@ namespace Tango.MachineStudio.RML.ViewModels
}
}
+ var rmlAfter = RmlDTO.FromObservable(ActiveRML);
+
await _active_context.SaveChangesAsync();
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlSaved, _authentication.CurrentUser, _rmlBeforeSave.Name, _rmlBeforeSave, rmlAfter, "RML saved using Machine Studio.");
+
+ _rmlBeforeSave = rmlAfter;
}
}
catch (Exception ex)
@@ -804,6 +828,8 @@ namespace Tango.MachineStudio.RML.ViewModels
var rmlFile = await Rml.FromRmlFile(db, json);
db.Rmls.Add(rmlFile);
+
+ _actionLogManager.InsertLog(BL.Enumerations.ActionLogType.RmlImported, _authentication.CurrentUser, rmlFile.Name, rmlFile, "RML imported from Machine Studio.");
}
await db.SaveChangesAsync();
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..bcbcb6d16 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,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
+using Tango.BL.ActionLogs;
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 +21,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 +61,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 +88,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 +117,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 +141,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..73d4c49cb 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,9 @@ 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;
namespace Tango.MachineStudio.Sites.ViewModels
{
@@ -17,6 +20,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;
@@ -69,9 +76,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,9 +91,12 @@ namespace Tango.MachineStudio.Sites.ViewModels
Site.Name = newSiteName;
Site.Description = "My site description";
_db.Sites.Add(Site);
+
+ _isNew = true;
}
else
{
+ _isNew = false;
Site = await _db.Sites.SingleOrDefaultAsync(x => x.Guid == siteGuid);
}
@@ -100,6 +112,8 @@ namespace Tango.MachineStudio.Sites.ViewModels
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);
+
+ _siteBeforeSave = SiteDTO.FromObservable(Site, site_rmls, site_catalogs, SelectedOrganization.Name);
}
private async void Save()
@@ -121,20 +135,38 @@ namespace Tango.MachineStudio.Sites.ViewModels
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);
+ //_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));
- foreach (var selectedRml in Rmls.SynchedSource)
+ foreach (var selectedRml in Rmls.SynchedSource.Where(x => !site_rmls.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_catalogs.Exists(y => y.CatalogGuid == x.Guid)))
{
_db.SitesCatalogs.Add(new SitesCatalog() { SiteGuid = Site.Guid, CatalogGuid = 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);
+ _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());