Пример #1
0
 public NamesEditor()
 {
     InitializeComponent();
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         NamesModel = new NamesModel();
     }
 }
Пример #2
0
        public NamesModel GetContext()
        {
            if (null == context)
            {
                context = new NamesModel();
            }

            return(context);
        }
Пример #3
0
        public IActionResult Index()
        {
            var model = new NamesModel();

            model.Names = new List <string>
            {
                "Carol Mason", "Amy Montoni", "Robert Morris", "Richard Thurmond", "Val Fox"
            };
            return(View(model));
        }
Пример #4
0
        /// <summary>
        /// This will sort the givenNameList object and return a List NamesModel order by lastName
        /// </summary>
        /// <param name="givenNameList"></param>
        /// <returns></returns>
        public List <NamesModel> sortGivenName(List <string> givenNameList)
        {
            try
            {
                //Create a List Object of NamesModel
                var namesModelList = new List <NamesModel>();

                //populate the List<NameModel>
                foreach (var item in givenNameList)
                {
                    //sort the item base on genericList object
                    //split each item then store it to an array object string
                    string[] splitObject = item.Split(" ");

                    //count the splitObject
                    int countSplitObject = splitObject.Count();

                    //convert splitObject array to list string object
                    //then remove specific element of list by subtructing the countSplitObject -1
                    //to locate the exact location of last name
                    var givenNameObjectList = new List <string>(splitObject);
                    givenNameObjectList.RemoveAt(countSplitObject - 1);

                    //Instantiate NamesModel
                    var namesModel = new NamesModel
                    {
                        //get the length on splitObject then subtract by -1 to locate
                        //the exact element then assigned the value to the property of lastName
                        LastName = splitObject[splitObject.Length - 1].ToString(),
                        //use string join to create single string object from givenNameObjectList array object
                        //then assign the value to the property of FirstName
                        GivenName = string.Join(" ", givenNameObjectList.ToArray())
                    };

                    //Then add the namesModel to List NamesModel Object
                    namesModelList.Add(namesModel);

                    //Order by LastName
                    namesModelList = namesModelList.AsQueryable().OrderBy(x => x.LastName).ToList();
                }

                return(namesModelList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception error was caught NameSortRepository:sortGivenName: {ex.Message}");
                throw ex;
            }
        }
Пример #5
0
        public void TestArrayFunctions()
        {
            var model = new NamesModel
            {
                Contact = new Contact
                {
                    Phone = new List <string> {
                        "650-123-0001", "650-123-0002"
                    }
                },
                Document = new MutableDocument("doc1")
            };

            Db.Save(model);

            var queryable = new DatabaseQueryable <NamesModel>(Db);
            var q         = from x in queryable
                            select x.Contact.Phone.Count;

            var numRows = VerifyQuery(q, (n, r) =>
            {
                r.Should().Be(2);
            });

            var q2 = from x in queryable
                     select new
            {
                TrueVal  = x.Contact.Phone.Contains("650-123-0001"),
                FalseVal = x.Contact.Phone.Contains("650-123-0003")
            };

            numRows = VerifyQuery(q2, (n, r) =>
            {
                r.TrueVal.Should().BeTrue();
                r.FalseVal.Should().BeFalse();
            });

            numRows.Should().Be(1);
        }
Пример #6
0
        public IActionResult Index()
        {
            List <SelectListItem> originalListItems = new List <SelectListItem>();
            List <SelectListItem> outputListItems   = new List <SelectListItem>();

            TextFileManipulator textFileManipulator = new TextFileManipulator();

            // Get Raw Name Data from file
            string rawData = textFileManipulator.GetRawFileData();

            // Convert Raw Name Data to list
            List <string> rawDataStringList = textFileManipulator.ConvertRawDataToList(rawData);

            foreach (var item in rawDataStringList)
            {
                originalListItems.Add(new SelectListItem()
                {
                    Text = item, Value = item, Selected = false
                });
            }

            // Sort Names list
            List <string> sortedStringList = textFileManipulator.SortStringList(rawDataStringList);

            // Delete previous sorted_names.txt
            if (System.IO.File.Exists("sorted_names.txt"))
            {
                System.IO.File.Delete("sorted_names.txt");
            }

            for (int i = 0; i < sortedStringList.Count - 1; i++)
            {
                string word            = sortedStringList[i];
                int    wordScore       = WordCalculations.CalculateWordScore(word, i + 1);
                string wordScoreString = wordScore.ToString();

                // Save sorted Names list to file
                textFileManipulator.WriteStringToFile(word, wordScoreString);
                // Output Sorted List to ListBox
                outputListItems.Add(new SelectListItem()
                {
                    Text = word + " - " + wordScoreString, Value = wordScoreString, Selected = false
                });
            }

            // Calculate Grand Total
            int grandTotal = WordCalculations.CalculateGrandTotalFromList(sortedStringList);

            // Question 1
            string highestTotalScoringName         = WordCalculations.CalculateHighestTotalScoringNameFromList(sortedStringList);
            int    highestTotalScoringNamePosition = WordCalculations.GetNamePositionFromList(sortedStringList, highestTotalScoringName);

            // Question 2
            string lowestTotalScoringName         = WordCalculations.CalculateLowestTotalScoringNameFromList(sortedStringList);
            int    lowestTotalScoringNamePosition = WordCalculations.GetNamePositionFromList(sortedStringList, lowestTotalScoringName);

            // Question 3
            Tuple <string, int> highestAlphabeticalValueAndName = WordCalculations.CalculateHighestAlphabeticalValueAndNameFromList(sortedStringList);
            string highestAlphabeticalValueName = highestAlphabeticalValueAndName.Item1;
            int    highestAlphabeticalValue     = highestAlphabeticalValueAndName.Item2;

            // Question 4
            Tuple <string, int> lowestAlphabeticalValueAndName = WordCalculations.CalculateLowestAlphabeticalValueAndNameFromList(sortedStringList);
            string lowestAlphabeticalValueName = lowestAlphabeticalValueAndName.Item1;
            int    lowestAlphabeticalValue     = lowestAlphabeticalValueAndName.Item2;

            // Question 5
            int averageAlphabeticalValue = WordCalculations.CalculateAverageAlphabeticalValueFromList(sortedStringList);

            NamesModel namesModel = new NamesModel()
            {
                OriginalNames                   = originalListItems,
                OutputNames                     = outputListItems,
                GrandTotal                      = grandTotal.ToString(),
                HighestTotalScoringName         = highestTotalScoringName,
                HighestTotalScoringNamePosition = highestTotalScoringNamePosition.ToString(),
                LowestTotalScoringName          = lowestTotalScoringName,
                LowestTotalScoringNamePosition  = lowestTotalScoringNamePosition.ToString(),
                HighestAlphabeticalValueName    = highestAlphabeticalValueName,
                HighestAlphabeticalValue        = highestAlphabeticalValue.ToString(),
                LowestAlphabeticalValueName     = lowestAlphabeticalValueName,
                LowestAlphabeticalValue         = lowestAlphabeticalValue.ToString(),
                AverageAlphabeticalValue        = averageAlphabeticalValue.ToString()
            };

            return(View(namesModel));
        }