/* S R F R O M P L S */ /*---------------------------------------------------------------------------- * %%Function: SRFromPls * %%Qualified: RwpSvc.Practice:Teams:RwpTeam.SRFromPls * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public static RSR SRFromPls(string sReason, List <string> plsDiff) { string s = sReason; foreach (string sItem in plsDiff) { s += sItem + ", "; } return(RSR.Failed(s)); }
/*---------------------------------------------------------------------------- * %%Function: ReportSr * %%Qualified: Rwp.AdminPage.ReportSr * %%Contact: rlittle * * report the SR to the web page * ----------------------------------------------------------------------------*/ private void ReportSr(RSR sr, string sOperation) { if (!sr.Result) { divError.Visible = true; divError.InnerText = sr.Reason; } else { divError.InnerText = String.Format("{0} returned no errors.", sOperation); } }
protected void EnableClearItems(object sender, EventArgs e) { RSR sr = CheckAdmin(); if (!sr.Result) { ReportSr(sr, "ipc"); return; } btnClearTeams.Enabled = true; }
private static RSR InsertAuthUser(string sIdentity, string sTeamName, Guid tenant, Sql sql) { RSR rsr; string sInsertUser = $"INSERT INTO rwllauth (PrimaryIdentity, Tenant, TeamID) VALUES ('{sIdentity}', '{tenant}', '{sTeamName}')"; rsr = RSR.FromSR(Sql.ExecuteNonQuery(sql, sInsertUser, null)); if (!rsr.Succeeded) { throw new Exception($"{rsr.Reason} ({sInsertUser})"); } return(rsr); }
protected void EnableDeleteSlots(object sender, EventArgs e) { RSR sr = CheckAdmin(); if (!sr.Result) { ReportSr(sr, "ipc"); return; } btnClearAllSlots.Enabled = true; btnClearLastYear.Enabled = true; }
/*---------------------------------------------------------------------------- * %%Function: DoDeleteTeams * %%Qualified: Rwp.AdminPage.DoDeleteTeams * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ protected void DoDeleteTeams(object sender, EventArgs e) { RSR sr = CheckAdmin(); if (!sr.Result) { ReportSr(sr, "ipc"); return; } // first download the current data... sr = m_apiInterop.CallService <RSR>("api/team/DeleteTeams", true); ReportSr(sr, "Delete Teams"); }
/*---------------------------------------------------------------------------- * %%Function: DoDelete2014Slots * %%Qualified: Rwp.AdminPage.DoDelete2014Slots * * Intended to be changed every year, currently hardcoded to 2014 (will be * 2018 once the 2019 season starts) * ----------------------------------------------------------------------------*/ protected void DoDelete2014Slots(object sender, EventArgs e) { RSR sr = CheckAdmin(); if (!sr.Result) { ReportSr(sr, "ipc"); return; } sr = m_apiInterop.CallService <RSR>($"api/slot/DeleteSlotsByYear/2014", true); ReportSr(sr, "Delete 2014 Slots"); }
/*---------------------------------------------------------------------------- * %%Function: DataGrid_DeleteItem * %%Qualified: Rwp.CalendarLinkPage.DataGrid_DeleteItem * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ void DataGrid_DeleteItem(Object sender, DataGridCommandEventArgs e) { // e.Item is the table row where the command is raised. For bound // columns, the value is stored in the Text property of a TableCell. TableCell itemCell = e.Item.Cells[0]; string item = itemCell.Text; // Remove the selected item from the data source RSR sr = m_apiInterop.CallService <RSR>($"api/calendar/RevokeCalendarLink/{item}", true); ReportSr(sr, "CreateLink"); // Rebind the data source to refresh the DataGrid control. BindSource(); }
RSR CheckAdmin() { RSR sr = new RSR(); if (m_userData.privs != Auth.UserPrivs.AdminPrivs) { sr.Result = false; sr.Reason = $"User does not have administrative privileges"; return(sr); } sr.Result = true; return(sr); }
/* P R E F L I G H T */ /*---------------------------------------------------------------------------- * %%Function: Preflight * %%Qualified: RwpSvc.Practice:Teams:RwpTeam.Preflight * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public RSR Preflight(TCore.Sql sql, out bool fTeamExists, out bool fAuthExists) { List <string> plsFail = new List <string>(); fTeamExists = false; fAuthExists = false; CheckLength(m_sName, "TeamName", 50, plsFail); CheckLength(m_sDivision, "Division", 10, plsFail); if (!Guid.TryParse(m_sTenant, out Guid g)) { plsFail.Add($"not a valid guid: {m_sTenant}"); } // check to see if the team already exists if (Sql.NExecuteScalar(sql, $"select count(*) from rwllteams where TeamName='{m_sName}'", null, 0) != 0) { fTeamExists = true; SqlQueryReadLine <TeamInfo> readLine = new SqlQueryReadLine <TeamInfo>( (SqlReader sqlr, ref TeamInfo ti) => { ti.TeamName = sqlr.Reader.GetString(0); ti.Division = sqlr.Reader.GetString(1); }); Sql.ExecuteQuery(sql, $"SELECT TeamName, Division FROM rwllteams WHERE TeamName='{m_sName}'", readLine, null); if (String.Compare(m_sDivision, readLine.Value.Division) != 0) { plsFail.Add($"division mismatch with existing team {m_sName}: {m_sDivision} != {readLine.Value.Division}"); } } // check to see if the auth already exists if (Sql.NExecuteScalar(sql, $"select count(*) from rwllauth where PrimaryIdentity='{m_sIdentity}' AND Tenant='{m_sTenant}' AND TeamID='{m_sName}'", null, 0) != 0) { fAuthExists = true; } if (plsFail.Count > 0) { return(SRFromPls($"preflight failed for team {m_sName}", plsFail)); } return(RSR.Success()); }
/*---------------------------------------------------------------------------- * %%Function: DoUploadSlots * %%Qualified: Rwp.AdminPage.DoUploadSlots * %%Contact: rlittle * * upload a csv file of slots to the server * ----------------------------------------------------------------------------*/ protected void DoUploadSlots(object sender, EventArgs e) { RSR sr; if ((fuSlots.PostedFile != null) && (fuSlots.PostedFile.ContentLength > 0)) { HttpContent content = new StreamContent(fuSlots.PostedFile.InputStream); sr = m_apiInterop.CallServicePut <RSR>("api/slot/PutSlots", content, true); } else { sr = new RSR(); sr.Result = false; sr.Reason = String.Format("Upload of file failed!"); } ReportSr(sr, "Upload Slots"); }
/* L O A D R W P T F R O M C S V */ /*---------------------------------------------------------------------------- * %%Function: LoadRwptFromCsv * %%Qualified: RwpSvc.Practice:Teams:CsvTeams.LoadRwptFromCsv * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public RSR LoadRwptFromCsv(string sLine, TCore.Sql sql, out RwpTeam rwpt, out bool fAdd, out List <string> plsDiff) { string[] rgs = LineToArray(sLine); SqlWhere sw = new SqlWhere(); fAdd = true; rwpt = new RwpTeam(); plsDiff = new List <string>(); sw.AddAliases(RwpTeam.s_mpAliases); try { rwpt.Name = GetStringVal(rgs, "TEAMNAME"); if (rwpt.Name == "") { return(RSR.Success()); } rwpt.Division = GetStringValNullable(rgs, "DIVISION"); rwpt.Password = GetStringValNullable(rgs, "PW"); rwpt.Created = GetDateValNullable(rgs, "DATECREATED"); rwpt.Updated = GetDateValNullable(rgs, "DATEUPDATED"); rwpt.FieldsReleased = GetIntVal(rgs, "FIELDSRELEASECOUNT"); rwpt.CagesReleased = GetIntVal(rgs, "CAGESRELEASECOUNT"); rwpt.FieldsReleasedToday = GetIntVal(rgs, "RELEASEDFIELDSTODAY"); rwpt.CagesReleasedToday = GetIntVal(rgs, "RELEASEDCAGESTODAY"); rwpt.ReleasedFieldsDate = GetDateValNullable(rgs, "RELEASEDFIELDSDATE"); rwpt.ReleasedCagesDate = GetDateValNullable(rgs, "RELEASEDCAGESDATE"); rwpt.Email1 = GetStringValNullable(rgs, "EMAIL1"); rwpt.Email2 = GetStringValNullable(rgs, "EMAIL2"); rwpt.Identity = GetStringValNullable(rgs, "IDENTITY"); rwpt.Tenant = GetStringValNullable(rgs, "TENANT"); } catch (Exception e) { return(RSR.Failed(e)); } return(RSR.Success()); }
/* G E T C S V */ /*---------------------------------------------------------------------------- * %%Function: GetCsv * %%Qualified: RwpSvc.Practice:Teams.GetCsv * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public RSR GetCsv(Stream stm) { CsvTeams csvt = new CsvTeams(); SqlWhere sw = new SqlWhere(); TextWriter tw = new StreamWriter(stm); sw.AddAliases(RwpTeam.s_mpAliases); m_plrwpt = new List <RwpTeam>(); // StringBuilder sb = new StringBuilder(4096); RSR sr = RSR.FromSR(Sql.ExecuteQuery(sw.GetWhere(RwpTeam.s_sSqlQueryString), this, Startup._sResourceConnString)); tw.WriteLine(csvt.Header()); foreach (RwpTeam rwpt in m_plrwpt) { tw.WriteLine(csvt.CsvMake(rwpt)); } tw.Flush(); return(RSR.Success()); }
/* D O D E L E T E S L O T S */ /*---------------------------------------------------------------------------- * %%Function: DoDeleteSlots * %%Qualified: Rwp.AdminPage.DoDeleteSlots * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ protected void DoDeleteSlots(object sender, EventArgs e) { RSR sr = CheckAdmin(); if (!sr.Result) { ReportSr(sr, "ipc"); return; } try { sr = m_apiInterop.CallService <RSR>("api/slot/DeleteAllSlots", true); } catch (Exception exc) { sr = new RSR(); sr.Result = false; sr.Reason = exc.Message; } ReportSr(sr, "Delete All Slots"); }
public IHttpActionResult PostCalendarLink([FromBody] CalendarLink linkItem) { RSR rsr = CalendarLinks.CalendarLinkItem.AddCalendarLinkItem(linkItem); return(Ok(rsr)); }
public IHttpActionResult RevokeCalendarLink(Guid guidLink) { RSR rsr = CalendarLinks.CalendarLinkItem.RevokeCalendarLink(guidLink); return(Ok(rsr)); }
public static RSR ClearTeams() { return(RSR.FromSR(Sql.ExecuteNonQuery("DELETE FROM rwllteams WHERE TeamName <> 'Administrator'", Startup._sResourceConnString))); }
/* I M P O R T C S V */ /*---------------------------------------------------------------------------- * %%Function: ImportCsv * %%Qualified: RwpSvc.Practice:Teams.ImportCsv * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public static RSR ImportCsv(Stream stm) { RSR sr; Sql sql; CsvTeams csv = new CsvTeams(); Random rnd = new Random(System.Environment.TickCount); TextReader tr = new StreamReader(stm); // process each line sr = RSR.FromSR(Sql.OpenConnection(out sql, Startup._sResourceConnString)); if (!sr.Result) { return(sr); } sr = RSR.FromSR(sql.BeginTransaction()); if (!sr.Result) { return(sr); } bool fHeadingRead = false; string sLine; int iLine = 0; RwpTeam rwpt; bool fAdd; List <string> plsDiff; try { while ((sLine = tr.ReadLine()) != null) { iLine++; if (sLine.Length < 2) { continue; } if (!fHeadingRead) { sr = csv.ReadHeaderFromString(sLine); if (!sr.Result) { throw new Exception(String.Format("Failed to make heading at line {0}: {1}", iLine - 1, sr.Reason)); } fHeadingRead = true; continue; } sr = csv.LoadRwptFromCsv(sLine, sql, out rwpt, out fAdd, out plsDiff); if (!sr.Result) { throw new Exception(String.Format("Failed to process line {0}: {1}", iLine - 1, sr.Reason)); } if (rwpt.Name == "") { continue; } // at this point, rwpt is a fully loaded team; check for errors and generate a passowrd if necessary bool fTeamExists = false; bool fAuthExists = false; sr = rwpt.Preflight(sql, out fTeamExists, out fAuthExists); if (!sr.Result) { throw new Exception(String.Format("Failed to preflight line {0}: {1}", iLine - 1, sr.Reason)); } if (!fTeamExists) { if (rwpt.Created == null) { rwpt.Created = DateTime.Now; } if (rwpt.Updated == null) { rwpt.Updated = rwpt.Created; } if (rwpt.ReleasedCagesDate == null) { rwpt.ReleasedCagesDate = DateTime.Parse("1/1/2013"); } if (rwpt.ReleasedFieldsDate == null) { rwpt.ReleasedFieldsDate = DateTime.Parse("1/1/2013"); } // at this point, we would insert... string sInsert = rwpt.SGenerateUpdateQuery(sql, fAdd); Sql.ExecuteNonQuery(sql, sInsert, null); } // now, add to the auth table (again checking to see if this already exists) if (!fAuthExists) { InsertAuthUser(rwpt.Identity, rwpt.Name, Guid.Parse(rwpt.Tenant), sql); } } } catch (Exception e) { sql.Rollback(); sql.Close(); return(RSR.Failed(e)); } sql.Commit(); sql.Close(); return(RSR.Success()); }