public static void Main(String[] args)
        {
            // Init: make connection to API, get all Ids
            ApiConnector apiConnection = new ApiConnector();
            int[] ids = apiConnection.GetAllIds();
            Types.Person[] minPeopleArr = new Types.Person[5];

            // To store the oldest person in our list of 5 youngest
            Types.Person oldest = null;

            int counter = 0; // To count off the first 5 IDs with valid phone numbers

            for (int i = 0; i < ids.Length; i++)
            {
                Person cur = apiConnection.MakeDetailsRequest(ids[i]);
                if (ApiConnector.IsValidPhoneNumber(cur.number))
                {
                    if (counter < 5)        // Case: processed under 5 valid users
                    {
                        minPeopleArr[counter] = cur;
                        if (oldest == null || cur.age > oldest.age)
                        {
                            oldest = cur;
                        }
                        counter++;
                    }
                    else if (cur.age < oldest.age)  // Case: current person is younger than oldest one stored
                    {
                        int maxIndex = Array.IndexOf(minPeopleArr, oldest);

                        minPeopleArr[maxIndex] = cur;

                        oldest = minPeopleArr.Max();

                    }
                }
            }

            // Finished, output the list of people
            Console.WriteLine("The following are the 5 youngest people with valid phone numbers");
            Console.WriteLine();
            Console.WriteLine("Id. Name, Age [Phone]");

            foreach (Person person in minPeopleArr)
            {
                Console.WriteLine(person.ToString());
            }

            Console.WriteLine("Hit Enter to quit");
            Console.Read();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Toggles <see cref="Deck.IsPinned"/> for the deck
 /// </summary>
 /// <param name="value">the new value</param>
 /// <param name="deck">the deck</param>
 public async void TogglePinned(bool value, Deck deck)
 {
     deck.IsPinned = value;
     await ApiConnector.PutAsync(deck);
 }
Exemplo n.º 3
0
 public FuncionariosController(ContextApplication context, ApiConnector apiConnector)
 {
     _context      = context;
     _apiConnector = apiConnector;
 }
 public void ApiConnector_Constructor_WithDelegate_Succeeds()
 {
     var connector = new ApiConnector(GetAccessToken);
 }
        private void reportsGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                // удалить здесь
                DialogResult dialogResult = MessageBox.Show("Вы действительно хотите удалить рапорт №" +
                                                            reportsGrid.CurrentRow.Cells[0].Value.ToString() + "?", "Удаление", MessageBoxButtons.YesNo,
                                                            MessageBoxIcon.Question,
                                                            MessageBoxDefaultButton.Button1);

                if (dialogResult == DialogResult.Yes)
                {
                    int index = e.RowIndex;
                    ApiConnector.deleteReport(reports[index]);
                    reports.RemoveAt(index);
                    AutoCompleteSourceForDocNum.RemoveAt(index);
                    reportsGrid.Rows.RemoveAt(index);
                    MessageBox.Show("Рапорт был успешно удален.", "Удаление рапорта",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            if (e.ColumnIndex == 3)
            {
                var identificationTable = new Dictionary <DataGridViewRow, ReportLine>();

                // открыть форму для редактирования рапорта

                Report currReport = reports.Find(report => reportsGrid.CurrentRow.Cells[0].Value.ToString() == report.doc_num.ToString());
                editingReport      = currReport;
                indexEditingReport = e.RowIndex;

                EditingReportForm editingReportForm = new EditingReportForm(currReport);
                ReportDocument    reportDocument    = editingReportForm.GetPanel;

                reportDocument.GetDocCreationTime.Value = DateTime.Parse(currReport.date);
                reportDocument.GetDocNumberTextBox      = currReport.doc_num.ToString();

                for (int i = 0; i < depNameComboBoxItems.Count; i++)
                {
                    reportDocument.GetDepSender.Items.Add(depNameComboBoxItems[i]);
                }
                string workshopName = ApiConnector.getWorkshop(currReport.workshop_sender_pk).workshop_name;
                int    index        = depNameComboBoxItems.IndexOf(workshopName);
                reportDocument.GetDepSender.SelectedIndex = index;

                DataGridView table = reportDocument.GetTable;
                table.AllowUserToAddRows  = false;
                reportDocument.SetDetails = details;

                foreach (var workshop in workshops)
                {
                    (table.Columns[3] as DataGridViewComboBoxColumn).Items.Add(workshop.workshop_name);
                }

                for (int i = 0; i < currReport.report_lines.Count; i++)
                {
                    table.Rows.Add();
                    table.Rows[i].Cells[1].Value   = currReport.report_lines[i].detail.cipher_detail;
                    table.Rows[i].Cells[2].Value   = currReport.report_lines[i].produced.ToString();
                    (table.Rows[i].Cells[0]).Value = currReport.report_lines[i].detail.detail_name;
                    table.Rows[i].Cells[3].Value   =
                        workshops.Find(workshop => workshop.workshop_pk == currReport.report_lines[i].workshop_receiver_pk).workshop_name;
                    identificationTable.Add(table.Rows[i], currReport.report_lines[i]);
                }
                reportDocument.identificationTable = identificationTable;
                table.AllowUserToAddRows           = true;
                editingReportForm.Show();
                editingReportForm.FormClosed += new FormClosedEventHandler(refreshFunc);
            }
        }
 public CarrinhoComprasController(ContextApplication dbContext, AuthenticatedUser user, DadosStorage dados, ApiConnector apiConnector)
 {
     _dbContext    = dbContext;
     _user         = user;
     _dados        = dados;
     _apiConnector = apiConnector;
 }
 //initialize control
 public UserControl InitControl(ApiConnector connector, string url)
 {
     return(new BaseSystemConstantControl(connector, url));
 }
Exemplo n.º 8
0
 public PermissionApiTests()
 {
     this._apiConnector = new ApiConnector();
     this._url          = "http://localhost:3423/api/Permission/";
     this._token        = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqbm93YWtAdGVzdC50ZXN0IiwianRpIjoiZjAyZGI0ZjQtY2UzMC00NWNjLTg3MjItYThlZTBhYWI1ZDZlIiwiaWF0IjoxNDg4MDMwMTgwLCJJZGVudGl0eVVzZXIiOiJVc2VyIiwibmJmIjoxNDg4MDMwMTgwLCJleHAiOjE0OTcwMzAxODAsImlzcyI6IlN1cGVyQXdlc29tZVRva2VuU2VydmVyIiwiYXVkIjoiaHR0cDovL2xvY2FsaG9zdDozNDIzLyJ9.afnnibWkpJhniqMP-wjBHl232ODe4CJ4vA0ssrZU58s";
 }
Exemplo n.º 9
0
 public HomeController(ILogger <HomeController> logger, ContextApplication dbContext, IWebHostEnvironment environment, ApiConnector apiConnector)
 {
     _logger       = logger;
     _dbContext    = dbContext;
     _environment  = environment;
     _apiConnector = apiConnector;
 }
Exemplo n.º 10
0
        private async void LoadRoom()
        {
            filmShowRoom = await ApiConnector.GetRoomService(filmShow.RoomId);

            LoadTickets();
        }
Exemplo n.º 11
0
 public UsuariosController(ApiConnector apiConnector)
 {
     _apiConnector = apiConnector;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Use proxy settings from Internet Explorer
 /// </summary>
 public static void SetUseProxySettingsFromInternetExplorer(bool use)
 {
     ApiConnector.SetUseProxySettingsFromInternetExplorer(use);
 }
Exemplo n.º 13
0
 //initialize control
 public UserControl InitControl(ApiConnector connector, string url)
 {
     return(new BaseKlr030Control(connector, url));
 }
Exemplo n.º 14
0
        private void inventarizationTable_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 3)
            {
                // удалить здесь
                DialogResult dialogResult = MessageBox.Show("Вы действительно хотите удалить ведомость №" +
                                                            inventarizationTable.CurrentRow.Cells[0].Value.ToString() + "?", "Удаление", MessageBoxButtons.YesNo,
                                                            MessageBoxIcon.Question,
                                                            MessageBoxDefaultButton.Button1);

                if (dialogResult == DialogResult.Yes)
                {
                    int index = e.RowIndex;
                    ApiConnector.deleteVedomost(vedomosts[index]);
                    vedomosts.RemoveAt(index);
                    AutoCompleteSourceForDocNum.RemoveAt(index);
                    inventarizationTable.Rows.RemoveAt(index);

                    MessageBox.Show("Ведомость была успешно удалена.", "Удаление ведомости",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            if (e.ColumnIndex == 2)
            {
                var identificationTable = new Dictionary <DataGridViewRow, VedomostLine>();

                // открыть форму для редактирования инвентаризации
                Vedomost currVedomost = vedomosts.Find(vedomost => inventarizationTable.CurrentRow.Cells[0].Value.ToString() == vedomost.doc_num.ToString());
                editingVedomost      = currVedomost;
                indexEditingVedomost = e.RowIndex;
                EditingInventarization  editingInventarizationForm = new EditingInventarization(currVedomost);
                InventarizationDocument inventarization            = editingInventarizationForm.GetPanel;
                inventarization.GetDocCreateDate.Value   = DateTime.Parse(currVedomost.creation_date);
                inventarization.GetDocNumberTextBox.Text = currVedomost.doc_num.ToString();

                for (int i = 0; i < depNameComboBoxItems.Count; i++)
                {
                    inventarization.GetDepComboBox.Items.Add(depNameComboBoxItems[i]);
                }

                string workshopName = ApiConnector.getWorkshop(currVedomost.workshop_pk).workshop_name;
                int    index        = depNameComboBoxItems.IndexOf(workshopName);
                inventarization.GetDepComboBox.SelectedIndex = index;
                DataGridView table = inventarization.GetTable;
                table.AllowUserToAddRows = false;

                inventarization.SetDetails = details;
                for (int i = 0; i < currVedomost.vedomost_lines.Count; i++)
                {
                    table.Rows.Add();
                    table.Rows[i].Cells[1].Value   = currVedomost.vedomost_lines[i].detail.cipher_detail;
                    table.Rows[i].Cells[2].Value   = currVedomost.vedomost_lines[i].amount;
                    (table.Rows[i].Cells[0]).Value = currVedomost.vedomost_lines[i].detail.detail_name;
                    identificationTable.Add(table.Rows[i], currVedomost.vedomost_lines[i]);
                }
                table.AllowUserToAddRows            = true;
                inventarization.identificationTable = identificationTable;
                editingInventarizationForm.Show();

                editingInventarizationForm.FormClosed += new FormClosedEventHandler(RefreshVedomosts);
            }
        }
 public ApiConnectorTests()
 {
     apiConnector = new ApiConnector(fakeLogger);
 }
Exemplo n.º 16
0
 //initialize control
 public UserControl InitControl(ApiConnector connector, string url)
 {
     return(new BaseCopyrightKindControl(connector, url));
 }
Exemplo n.º 17
0
 public void PageNotZeroTest()
 {
     ApiConnector.SetFactory(null);
     ((ApiConnector)ApiConnector.Instance).PrepareRequest(string.Empty, page: 0, perPage: 10);
 }
Exemplo n.º 18
0
 public ProdutosController(ContextApplication context, IWebHostEnvironment webHost, DadosStorage dados, ApiConnector apiConnector)
 {
     _context      = context;
     _WebHost      = webHost;
     _dados        = dados;
     _apiConnector = apiConnector;
 }
Exemplo n.º 19
0
 public void PerPageNotLessThanZeroTest()
 {
     ApiConnector.SetFactory(null);
     ((ApiConnector)ApiConnector.Instance).PrepareRequest(string.Empty, page: 5, perPage: -5);
 }
        IEnumerable <Report> getReportstsList()
        {
            List <Report> reports = null;

            try
            {
                reports = (List <Report>)ApiConnector.getReports();
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("Отсутствует подключение к сети Интернет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(new List <Report>());
            }

            if (searchFilterBar1.isDocumentNumberChecked())
            {
                int documentNumber = searchFilterBar1.documentNumber();
                var report         = reports.Find(report => report.doc_num == documentNumber);
                if (report != null)
                {
                    reports = new List <Report> {
                        report
                    }
                }
                ;
                else
                {
                    reports.Clear();
                }
            }
            else
            {
                if (searchFilterBar1.isDateSelected())
                {
                    DateTime date = searchFilterBar1.getDate();

                    string format = "yyyy-MM-dd";
                    reports = reports.FindAll(report =>
                                              DateTime.ParseExact(report.date, format, CultureInfo.InvariantCulture) == date);
                }

                if (searchFilterBar1.isPeriodSelected())
                {
                    DateTime lowestDate  = searchFilterBar1.getLowestDate();
                    DateTime highestDate = searchFilterBar1.getHighestDate();

                    string format = "yyyy-MM-dd";
                    reports = reports.FindAll(report =>
                                              DateTime.ParseExact(report.date, format, CultureInfo.InvariantCulture) >= lowestDate &&
                                              DateTime.ParseExact(report.date, format, CultureInfo.InvariantCulture) <= highestDate);
                }

                if (searchFilterBar1.isWorkshopChecked())
                {
                    string senderWorkshop = searchFilterBar1.getWorkshop();

                    var workshop = ApiConnector.getWorkshop(senderWorkshop);
                    reports = reports.FindAll(report => report.workshop_sender_pk == workshop.workshop_pk);
                }
            }

            return(reports);
        }
 public void ApiConnector_Constructor_WithoutDelegate_Fails()
 {
     var connector = new ApiConnector(null);
 }
 //initialize control
 public UserControl InitControl(ApiConnector connector, string url)
 {
     return(new BaseGenreTypeControl(connector, url));
 }
Exemplo n.º 23
0
        public bool AddToDb(MlContext ctx, string username, out string msg)
        {
            // Extract id from user-provided url
            int id;

            try {
                id = int.Parse(UrlRegex.Match(Url).Groups[2].Value);
            } catch {
                msg = "Invalid URL";
                return(false);
            }

            // Check if the submission already exists. Prevents api spam
            // I'd use .Any() but it's throwing a lot of `InvalidOperationException: No coercion operator is defined
            // between types 'System.Int16' and 'System.Boolean'.` exceptions so I went with the gimmicky option due to
            // time constraints
            if (ctx.Submissions.Where(t => t.Id == id).ToList().Any())
            {
                msg = "Movie already exists";
                return(false);
            }

            // Attempt to get movie details from external API
            Entry entry;

            try {
                entry = ApiConnector.AsyncGet(id).Result;
                if (entry == null)
                {
                    throw new Exception();
                }
            } catch {
                msg = "An error occurred while fetching the data";
                return(false);
            }

            // Attempt to add to database
            try {
                ctx.Submissions.Add(new Submission {
                    Id         = entry.MalId,
                    UserId     = ctx.Users.First(t => t.Username.Equals(username)).Id,
                    Url        = Url,
                    Title      = entry.Title,
                    Duration   = entry.Duration,
                    Episodes   = entry.Episodes,
                    ImageUrl   = entry.ImageUrl,
                    Score      = entry.Score,
                    Type       = entry.Type,
                    TrailerUrl = entry.TrailerUrl,
                    Rating     = entry.Rating,
                    Synopsis   = entry.Synopsis,
                    Genres     = entry.Genres.Select(t => t.Name).Aggregate((i, j) => i + ", " + j)
                });

                ctx.SaveChanges();
            } catch (Exception ex) {
                msg = ex.Message;
                msg = "An exception occurred while processing the request";
                return(false);
            }

            msg = "Successfully added";
            return(true);
        }