public ActionResult AddEditPost(string id, string date, string band1, string band2, string band3, string band4, string notes)
        {
            // seperate the defined values for each band from their ids
            int    band1ID    = Convert.ToInt32(band1.Split('|')[0]);
            int    band2ID    = Convert.ToInt32(band2.Split('|')[0]);
            int    band3ID    = Convert.ToInt32(band3.Split('|')[0]);
            int    band4ID    = Convert.ToInt32(band4.Split('|')[0]);
            string first      = band1.Split('|')[1];
            string second     = band2.Split('|')[1];
            double multiplier = Convert.ToDouble(band3.Split('|')[1]);
            double tolerance  = Convert.ToDouble(band4.Split('|')[1]);

            // calculate the resistance and its range from the tolerance
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();
            var resistance = service.CalculateResistance(first, second, multiplier, tolerance);

            // check if this is for an existing entry and therefore and update not an add
            Entry entry = new Entry(Convert.ToInt32(id), Convert.ToDateTime(date), band1ID, band2ID, band3ID, band4ID, resistance, notes);

            if (Convert.ToInt32(id) > 0)
            {
                _entriesRepository.UpdateEntry(entry);
            }
            else
            {
                _entriesRepository.AddEntry(entry);
            }

            return(RedirectToAction("ViewDelete"));
        }
Exemple #2
0
        public void CalculateResistance()
        {
            // Arrange
            ResistorCalculatorService.ResistorCalculatorServiceClient service = new ResistorCalculatorService.ResistorCalculatorServiceClient();

            // Act
            // calculate the resitance locally for Red - Violet - Green - Brown
            double rootValue       = 27 * 100000;
            double resistanceMin   = rootValue * (.99);
            double resistanceMax   = rootValue * (1.01);
            string resistanceLocal = resistanceMin.ToString() + " - " + resistanceMax.ToString();

            // calculate the resistance from the service by their values Red(2) - Violet(7) - Green(100000) - Brown(.01)
            string resistanceService = service.CalculateResistance("2", "7", 100000, .01);

            // Assert
            Assert.AreEqual(resistanceLocal, resistanceService);
        }