public static async Task LogAsync(Credentials user, LogActivityType activity, string message) { using (var repo = new Repository()) { var log = repo.Create<activity_log>(); log.action_id = (int) activity; log.credentials_id = Authentication.Credentials.CredId; log.message = message; log.created = await repo.GetNowAsync(); repo.Add(log); await repo.SaveChangesAsync(); } }
public AuthenticatedArgs(Credentials cred) { this.Credentials = cred; }
public static async void NotifyAboutForms(Credentials user) { using (var repo = new Repository()) { var formList = new List<form>(); if (user.IsEdu) { var kind = (await repo.GetEdu(user.EduId)).edu_kind; formList = kind.forms.ToList(); } else if (user.IsMunicipality) { formList = await repo.GetMunicipalityForms(); } else if (user.IsRegion) { formList = await repo.GetRegionForms(); } var now = await repo.GetNowAsync(); foreach (var form in formList) { IForm uploadedForm = null; if (user.IsEdu) uploadedForm = await repo.FindEduFormData(form.form_id, user.EduId, now.Year); else if (user.IsMunicipality) uploadedForm = await repo.FindMunicipalityFormData(form.form_id, user.MunitId, now.Year); else if (user.IsRegion) uploadedForm = await repo.FindRegionFormData(form.form_id, user.RegionId, now.Year); if (uploadedForm != null) continue; var timeRemaining = await form.TimeRemainingAsync(); if (timeRemaining == TimeSpan.Zero || timeRemaining.Days >= 30) continue; var warn = new Notifications.ExpireWarn() { Now = now, TimeRemaining = timeRemaining, FormName = form.name, FormId = form.form_id }; Notifications.Add(warn); } } }
public static Task LogLogoutAsync(Credentials user) { return LogAsync(user, LogActivityType.Logout, Authentication.Credentials.Name); }
private async void TriggerControlsWithPrivilegies(Credentials user) { using (var repo = new Repository()) { tilePassport.Tag = user.IsEdu ? user.EduId : (user.IsMunicipality ? user.MunitId : 0); var syncCtx = SynchronizationContext.Current; var view = windowsUIViewMain; if (user.IsRegion || user.IsMinistry) { tileForms.Click += (sender, args) => Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.Edu, syncCtx); tileArchiveForms.Click += (sender, args) => Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.Edu, syncCtx); tileAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu, syncCtx); tileArchiveAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu, syncCtx); tileMunicipalityForms.Click += (sender, args) => Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.Municipality, syncCtx); tileMunicipalityArchiveForms.Click += (sender, args) => Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.Municipality, syncCtx); tileMunicipalityAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, false, FormType.OtherMunicipality, syncCtx); tileMunicipalityArchiveAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityMunicipalityLayerAction.Invoke(sender, args, view, true, FormType.OtherMunicipality, syncCtx); var regionAction = Actions.LoadRegionsLayerAction; if (user.IsRegion) { regionAction = Actions.LoadRegionFormsLayerAction; } tileRegionForms.Click += (sender, args) => regionAction.Invoke(sender, args, view, false, FormType.Region, syncCtx); tileRegionAdditionalForms.Click += (sender, args) => regionAction.Invoke(sender, args, view, false, FormType.OtherRegion, syncCtx); tileRegionArchiveForms.Click += (sender, args) => regionAction.Invoke(sender, args, view, true, FormType.Region, syncCtx); tileRegionArchiveAdditionalForms.Click += (sender, args) => regionAction.Invoke(sender, args, view, true, FormType.OtherRegion, syncCtx); } else if (user.IsMunicipality) { var munit = await repo.GetMunicipality(user.MunitId); tileMunicipalityForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit); tileMunicipalityForms.Click += (sender, args) => Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, false, FormType.Municipality, syncCtx); tileMunicipalityArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive"); tileMunicipalityArchiveForms.Click += (sender, args) => Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, true, FormType.Municipality, syncCtx); tileMunicipalityAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit); tileMunicipalityAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, false, FormType.OtherMunicipality, syncCtx); tileMunicipalityArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive"); tileMunicipalityArchiveAdditionalForms.Click += (sender, args) => Actions.LoadMunicipalityFormsLayerAction.Invoke(sender, args, view, true, FormType.OtherMunicipality, syncCtx); tileForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit); tileForms.Click += (sender, args) => Actions.LoadEduKindLayerAction.Invoke(sender, args, view, false, FormType.Edu, syncCtx); tileArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive"); tileArchiveForms.Click += (sender, args) => Actions.LoadEduKindLayerAction.Invoke(sender, args, view, true, FormType.Edu, syncCtx); tileAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit); tileAdditionalForms.Click += (sender, args) => Actions.LoadEduKindLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu, syncCtx); tileArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, munit, "archive"); tileArchiveAdditionalForms.Click += (sender, args) => Actions.LoadEduKindLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu, syncCtx); pageGroupQueries.Items.Clear(); pageGroupQueries.Items.Add(documentQueriesEdu); tabbedGroupStatistics.Items.Remove(documentMunicipalityFormStatistics); tabbedGroupStatistics.Items.Remove(documentMunicipalityFormDetailedStatistics); } else if (user.IsEdu) { var edu = await repo.GetEdu(user.EduId); tileForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu); tileForms.Click += (sender, args) => Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, false, FormType.Edu, syncCtx); tileArchiveForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu, "archive"); tileArchiveForms.Click += (sender, args) => Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, true, FormType.Edu, syncCtx); tileAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu); tileAdditionalForms.Click += (sender, args) => Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, false, FormType.OtherEdu, syncCtx); tileArchiveAdditionalForms.Tag = TagHelper.GetTag(TagHelper.TagType.Tile, edu, "archive"); tileArchiveAdditionalForms.Click += (sender, args) => Actions.LoadEduFormsLayerAction.Invoke(sender, args, view, true, FormType.OtherEdu, syncCtx); pageGroupQueries.Items.Clear(); } if (user.AccessRights.HasFlag(AccessRights.EduForms)) { tileContainerMain.Items.Add(tileForms); tileContainerMain.Items.Add(tileArchiveForms); tileContainerMain.Items.Add(tileAdditionalForms); tileContainerMain.Items.Add(tileArchiveAdditionalForms); } if (user.AccessRights.HasFlag(AccessRights.MunitForms)) { tileContainerMain.Items.Add(tileMunicipalityForms); tileContainerMain.Items.Add(tileMunicipalityArchiveForms); tileContainerMain.Items.Add(tileMunicipalityAdditionalForms); tileContainerMain.Items.Add(tileMunicipalityArchiveAdditionalForms); } if (user.AccessRights.HasFlag(AccessRights.RegionForms)) { tileContainerMain.Items.Add(tileRegionForms); tileContainerMain.Items.Add(tileRegionArchiveForms); tileContainerMain.Items.Add(tileRegionAdditionalForms); tileContainerMain.Items.Add(tileRegionArchiveAdditionalForms); } if (user.AccessRights.HasFlag(AccessRights.Statistics)) { tileContainerMain.Items.Add(tileFormStatistics); } if (user.AccessRights.HasFlag(AccessRights.UploadForm)) { tileContainerMain.Items.Add(tileSpreadsheet); } if (user.AccessRights.HasFlag(AccessRights.Dictionaries)) { tileContainerMain.Items.Add(tileDictionaries); tileContainerMain.Items.Add(tileMessageList); } if (user.AccessRights.HasFlag(AccessRights.Queries)) { tileContainerMain.Items.Add(tileQueries); } if (user.AccessRights.HasFlag(AccessRights.CreateQueries)) { tileContainerMain.Items.Add(tileCreateQuery); } if (user.AccessRights.HasFlag(AccessRights.Passport)) { tileContainerMain.Items.Add(tilePassport); } if (user.AccessRights.HasFlag(AccessRights.SendMessage)) { tileContainerMain.Items.Add(tileMessage); } if (user.IsEdu) { tileForms.Tag = string.Format("Forms{0}", (int) FormType.Edu); tileAdditionalForms.Tag = string.Format("Forms{0}", (int) FormType.OtherEdu); } var items = new BaseTile[tileContainerMain.Items.Count]; tileContainerMain.Items.CopyTo(items, 0); tileContainerMain.Items.Clear(); tileContainerMain.Items.AddRange(items.OrderBy(t => t.Group)); labelLoggedUser.Text = user.Name; labelLoggedUser.Cursor = Cursors.Hand; if (user.IsEdu) { labelLoggedUser.Click += (s, e) => { windowsUIViewMain.ActivateContainer(pagePassport); }; } GuiUtility.NotifyAboutForms(user); if (Notifications.List.Count > 0) flyoutPanelNotifications.ShowPopup(); labelLoggedUser.Text = Authentication.Credentials.Name; ((HostForm)MdiParent).BarVisible = Authentication.Credentials.IsRegion; } }