protected void gvShareKeys_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } ShareKey sk = ShareKey.ShareKeyWithID(e.Keys[0].ToString()); if (sk == null) { throw new InvalidOperationException("Unknown key: " + e.Keys[0].ToString()); } sk.Name = e.NewValues["Name"].ToString(); sk.CanViewCurrency = (bool)e.NewValues["CanViewCurrency"]; sk.CanViewTotals = (bool)e.NewValues["CanViewTotals"]; sk.CanViewFlights = (bool)e.NewValues["CanViewFlights"]; sk.CanViewAchievements = (bool)e.NewValues["CanViewAchievements"]; sk.CanViewVisitedAirports = (bool)e.NewValues["CanViewVisitedAirports"]; if (sk.FCommit()) { gvShareKeys.EditIndex = -1; RefreshSharekeys(); } else { e.Cancel = true; } }
protected void btnCreateShareLink_Click(object sender, EventArgs e) { ShareKey sk = new ShareKey(Page.User.Identity.Name) { Name = txtShareLinkName.Text, CanViewCurrency = ckShareLinkCurrency.Checked, CanViewFlights = ckShareLinkFlights.Checked, CanViewTotals = ckShareLinkTotals.Checked, CanViewAchievements = ckShareLinkAchievements.Checked, CanViewVisitedAirports = ckShareLinkAirports.Checked }; try { sk.FCommit(); txtShareLinkName.Text = string.Empty; ckShareLinkCurrency.Checked = ckShareLinkFlights.Checked = ckShareLinkTotals.Checked = ckShareLinkAchievements.Checked = ckShareLinkAirports.Checked = true; gvShareKeys.EditIndex = -1; RefreshSharekeys(); } catch (MyFlightbookValidationException ex) { lblShareKeyErr.Text = ex.Message; } }
public async Task <ServiceResult> CreateShareKeyAsync(Guid carId, Guid userId, string coOwnerRole) { var car = await _carRepository.GetCarByIdAsync(carId); if (car == null) { return(FailedResult("Car doesn't exist", 404)); } if (!CheckPermissions(car, userId, coOwnerRole)) { return(FailedResult("User can't do it with this car", 401)); } var shareKey = new ShareKey { IssuerId = userId, CarId = carId, UserCarRoleId = coOwnerRole, Used = false }; if (!await _shareKeyRepository.CreateShareKeyAsync(shareKey)) { return(FailedResult("Something went wrong", 500)); } var respone = new CreateShareKeyResponse { Success = true, ShareKey = shareKey.ShareKeyId }; return(SuccessResult(respone, 201)); }
/// <summary> /// We set up the sharekey here because mfblogbook could try to load first - if it's an invalid sharekey, then we'll do the redirect without a db hit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Init(object sender, EventArgs e) { string guid = util.GetStringParam(Request, "g"); ShareKey sk = ShareKey.ShareKeyWithID(guid); if (sk == null) { Response.Redirect("~/HTTP403.htm"); } CurrentShareKey = sk; mfbLogbook.User = sk.Username; }
protected void gvShareKeys_RowCommand(object sender, GridViewCommandEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (String.Compare(e.CommandName, "_Delete", StringComparison.OrdinalIgnoreCase) == 0) { ShareKey sk = ShareKey.ShareKeyWithID(e.CommandArgument.ToString()); if (sk != null) { sk.FDelete(); RefreshSharekeys(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShareKey sk = CurrentShareKey; // set in Page_Init Profile pf = Profile.GetUser(sk.Username); lblHeader.Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.LogbookForUserHeader, pf.UserFullName); // Indicate success. sk.FUpdateAccess(); int privCount = sk.PrivilegeCount; apcAnalysis.Container.Style["display"] = apcCurrency.Container.Style["display"] = apcTotals.Container.Style["display"] = apcFilter.Container.Style["display"] = apcAchievements.Container.Style["display"] = apcAirports.Container.Style["display"] = "none"; if (sk.CanViewCurrency) { apcCurrency.Container.Style["display"] = "inline-block"; mfbCurrency.Visible = true; mfbCurrency.UserName = sk.Username; mfbCurrency.RefreshCurrencyTable(); if (privCount == 1) // if ONLY showing currency, expand it and hide the accordion { pnlAccordionMenuContainer.Visible = false; SetAccordionPane(acpPaneCurrency.ID); } } if (sk.CanViewTotals) { apcTotals.Container.Style["display"] = "inline-block"; mfbTotalSummary.Visible = true; mfbTotalSummary.Username = sk.Username; mfbTotalSummary.CustomRestriction = new FlightQuery(sk.Username); // will call bind if (privCount == 1) // if ONLY showing totals, expand it and hide the accordion { pnlAccordionMenuContainer.Visible = false; SetAccordionPane(acpPaneTotals.ID); } } if (sk.CanViewFlights) { apcAnalysis.Container.Style["display"] = apcFilter.Container.Style["display"] = "inline-block"; mfbLogbook.Visible = true; mfbSearchForm.Username = mfbLogbook.User = sk.Username; mfbLogbook.RefreshData(); mfbChartTotals.Visible = true; mfbChartTotals.Refresh(mfbLogbook.Data); } if (sk.CanViewAchievements) { apcAchievements.Container.Style["display"] = "inline-block"; mfbRecentAchievements.Visible = mvBadges.Visible = true; List <Badge> lst = new Achievement(sk.Username).BadgesForUser(); if (lst == null || lst.Count == 0) { mvBadges.SetActiveView(vwNoBadges); } else { mvBadges.SetActiveView(vwBadges); rptBadgeset.DataSource = BadgeSet.BadgeSetsFromBadges(lst); rptBadgeset.DataBind(); } mfbRecentAchievements.AutoDateRange = true; mfbRecentAchievements.Refresh(sk.Username, DateTime.MaxValue, DateTime.MinValue, false); lblRecentAchievementsTitle.Text = mfbRecentAchievements.Summary; if (privCount == 1) // if ONLY showing achievements, expand it { SetAccordionPane(acpPaneAchievements.ID); } } if (sk.CanViewVisitedAirports) { apcAirports.Container.Style["display"] = "inline-block"; Restriction.UserName = mfbSearchForm.Username = mfbLogbook.User = sk.Username; if (privCount == 1) // if ONLY showing airports, expand it { SetAccordionPane(acpPaneAirports.ID); } } } if (mfbLogbook.Visible && apcAnalysis.Visible) { mfbChartTotals.SourceData = mfbLogbook.Data; // do this every time, since charttotals doesn't persist its data. } if (CurrentShareKey.CanViewVisitedAirports) { RefreshVisitedAirports(); } }
protected void RefreshSharekeys() { gvShareKeys.DataSource = ShareKey.ShareKeysForUser(Page.User.Identity.Name); gvShareKeys.DataBind(); }
private async Task <bool> MakeShareKeyUsed(ShareKey shareKey) { shareKey.Used = true; return(await _shareKeyRepository.UpdateShareKeyAsync(shareKey)); }
public async Task <bool> UpdateShareKeyAsync(ShareKey shareKey) { _context.ShareKeys.Update(shareKey); return(await SaveChangesAsync()); }
public async Task <bool> CreateShareKeyAsync(ShareKey shareKey) { await _context.ShareKeys.AddAsync(shareKey); return(await SaveChangesAsync()); }