From 63579cee4493c4a8e3d64348d644fd2eecaca055 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 21 Jan 2019 13:53:00 +0200 Subject: PPC v1.0.0 --- .../PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs index 516349a18..f926a0f4c 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LoadingViewVM.cs @@ -21,6 +21,7 @@ using Tango.PPC.Jobs; using Tango.SharedUI; using System.Data.Entity; using Tango.BL.Enumerations; +using Tango.BL.Builders; namespace Tango.PPC.UI.ViewModels { @@ -79,7 +80,19 @@ namespace Tango.PPC.UI.ViewModels if (db.Users.Count() == 1 || machine.AutoLogin) { - var user = await db.Users.FirstAsync(); + var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync(); + + if (!user.HasRole(Roles.PPCUser)) + { + var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser); + user.Roles.Add(role); + db.UsersRoles.Add(new BL.Entities.UsersRole() + { + User = user, + Role = role, + }); + await db.SaveChangesAsync(); + } LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView..."); await AuthenticationProvider.Login(user.Email, user.Password, false); -- cgit v1.3.1