/// <summary>
        ///     Updates an given Testvalue from the view model
        /// </summary>
        /// <param name="viewModel">the data from the view</param>
        /// <returns>the updated test value</returns>
        public TestValue UpdateRewetTest(InkoRewetEditViewModel viewModel)
        {
            var testValue = TestBll.GetTestValue(viewModel.TestValueId);

            if (testValue.IsNull() || (testValue.ArticleTestType != ArticleType.IncontinencePad) ||
                (testValue.IncontinencePadTestValue.TestType != TestTypeIncontinencePad.RewetFree))
            {
                Logger.Error("Old Test not found in DB");
                return(null);
            }
            testValue.LastEditedDateTime         = DateTime.Now;
            testValue.LastEditedPerson           = viewModel.TestPerson;
            testValue.DayInYearOfArticleCreation = viewModel.ProductionCodeDay;
            testValue.IncontinencePadTestValue.IncontinencePadTime = viewModel.ProductionCodeTime;
            testValue.IncontinencePadTestValue.ExpireMonth         = viewModel.ExpireMonth;
            testValue.IncontinencePadTestValue.ExpireYear          = viewModel.ExpireYear;
            testValue.IncontinencePadTestValue.RewetFreeDryValue   = viewModel.FPDry;
            testValue.IncontinencePadTestValue.RewetFreeWetValue   = viewModel.FPWet;
            testValue.IncontinencePadTestValue.TestType            = TestTypeIncontinencePad.RewetFree;

            TestServiceHelper.UpdateNotes(viewModel.Notes, testValue);

            testValue.IncontinencePadTestValue = CalculateInkoRewetValues(testValue.IncontinencePadTestValue, viewModel.TestSheetId);

            TestBll.UpdateTestValue(testValue);
            return(testValue);
        }
        public void UpdateRewetTestBaseTest()
        {
            var viewModel = new InkoRewetEditViewModel
            {
                TestPerson         = "Hans",
                TestValueId        = -1,
                TestSheetId        = 1,
                ProductionCodeTime = new TimeSpan(12, 34, 0),
                ProductionCodeDay  = 123,
                FPDry = 20.0,
                FPWet = 20.2,
                Notes = new List <TestNote> {
                    new TestNote {
                        ErrorCodeId = 1, Id = 1, Message = "Testnote"
                    }
                }
            };
            var testValueReturnedFromDb = new TestValue
            {
                TestSheetId                = 1,
                CreatedDateTime            = new DateTime(2016, 1, 2),
                LastEditedDateTime         = new DateTime(2016, 1, 2),
                CreatedPerson              = "Fritz",
                LastEditedPerson           = "Fritz",
                DayInYearOfArticleCreation = 123,
                ArticleTestType            = ArticleType.IncontinencePad,
                TestValueNote              = new List <TestValueNote> {
                    new TestValueNote {
                        ErrorId = 1, Message = "Testnote"
                    }
                },
                IncontinencePadTestValue = new IncontinencePadTestValue
                {
                    IncontinencePadTime = new TimeSpan(11, 11, 0),
                    TestType            = TestTypeIncontinencePad.RewetFree
                }
            };
            var testSheetDataFromDb       = GetTestSheetTestData();
            var productionOrderDataFromDb = GetProductionOrderTestData();

            var babyDiaperBll = MockHelperBll.GetTestBllForSavingAndUpdating(testSheetDataFromDb, productionOrderDataFromDb, testValueReturnedFromDb);

            var testServiceHelper = MockHelperTestServiceHelper.GetTestServiceHelperForUpdating();

            var target = new InkoRewetServiceHelper(new NLogLoggerFactory())
            {
                TestBll           = babyDiaperBll,
                TestServiceHelper = testServiceHelper
            };

            var actual = target.UpdateRewetTest(viewModel);

            Assert.Equal(testValueReturnedFromDb, actual);
            Assert.Equal(20, actual.IncontinencePadTestValue.RewetFreeDryValue);
            Assert.Equal(20.2, actual.IncontinencePadTestValue.RewetFreeWetValue);
            Assert.Equal(0.2, actual.IncontinencePadTestValue.RewetFreeDifference, 2);
            Assert.Equal("Hans", actual.LastEditedPerson);
            Assert.Equal("Fritz", actual.CreatedPerson);
            Assert.NotEqual(new DateTime(2016, 1, 2), actual.LastEditedDateTime);
        }
Exemplo n.º 3
0
 public ActionResult AddNote(InkoRewetEditViewModel viewModel)
 {
     if (viewModel.Notes.IsNull())
     {
         viewModel.Notes = new List <TestNote>();
     }
     viewModel.Notes.Add(new TestNote());
     return(View("Edit", viewModel));
 }
        public void SaveNewRewetTestBaseTest()
        {
            var viewModel = new InkoRewetEditViewModel
            {
                TestPerson         = "Hans",
                TestValueId        = -1,
                TestSheetId        = 1,
                ProductionCodeTime = new TimeSpan(12, 34, 0),
                ProductionCodeDay  = 123,
                FPDry = 20.0,
                FPWet = 20.2,
                Notes = new List <TestNote> {
                    new TestNote {
                        ErrorCodeId = 1, Id = 1, Message = "Testnote"
                    }
                }
            };
            var testValueReturnedFromHelper = new TestValue
            {
                TestSheetId                = 1,
                CreatedDateTime            = new DateTime(2016, 1, 2),
                LastEditedDateTime         = new DateTime(2016, 1, 2),
                CreatedPerson              = "Hans",
                LastEditedPerson           = "Hans",
                DayInYearOfArticleCreation = 123,
                ArticleTestType            = ArticleType.IncontinencePad,
                TestValueNote              = new List <TestValueNote> {
                    new TestValueNote {
                        ErrorId = 1, Message = "Testnote"
                    }
                }
            };
            var testSheetDataFromDb       = GetTestSheetTestData();
            var productionOrderDataFromDb = GetProductionOrderTestData();

            var testBll           = MockHelperBll.GetTestBllForSavingAndUpdating(testSheetDataFromDb, productionOrderDataFromDb, null);
            var testServiceHelper = MockHelperTestServiceHelper.GetTestServiceHelperCreateNewTestValue(testValueReturnedFromHelper);

            var target = new InkoRewetServiceHelper(new NLogLoggerFactory())
            {
                TestBll           = testBll,
                TestServiceHelper = testServiceHelper
            };

            var actual = target.SaveNewRewetTest(viewModel);

            Assert.Equal(testValueReturnedFromHelper, actual);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Saves or updates the InkoRewetEditViewModel
        /// </summary>
        /// <param name="viewModel">The viewmodel which will be saved or updated</param>
        /// <returns>The saved or updated TestValue</returns>
        public TestValue Save(InkoRewetEditViewModel viewModel)
        {
            TestValue testValue;

            try
            {
                testValue = viewModel.TestValueId <= 0
                    ? InkoRewetServiceHelper.SaveNewRewetTest(viewModel)
                    : InkoRewetServiceHelper.UpdateRewetTest(viewModel);
                InkoRewetServiceHelper.UpdateRewetAverageAndStv(viewModel.TestSheetId);
            }
            catch (Exception e)
            {
                Logger.Error("Update oder Create new Test Value ist fehlgeschlagen: " + e.Message);
                testValue = null;
            }
            return(testValue);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Gets the InkoRewetEditViewModel for edit
        /// </summary>
        /// <param name="testSheetId">The Id of the test sheet where the Inko rewet test is for</param>
        /// <returns>The InkoRewetEditViewModel</returns>
        public InkoRewetEditViewModel GetNewInkoRewetEditViewModel(Int32 testSheetId)
        {
            var testSheet = TestBll.GetTestSheetInfo(testSheetId);

            if (testSheet.IsNull() || (testSheet.ArticleType != ArticleType.IncontinencePad))
            {
                Logger.Error("TestBlatt mit id " + testSheetId + "existiert nicht in DB!");
                return(null);
            }

            var errors     = TestBll.GetAllNoteCodes();
            var errorCodes = errors.Select(error => new ErrorCode {
                ErrorId = error.ErrorId, Name = error.ErrorCode + " - " + error.Value
            })
                             .ToList();

            var viewModel = new InkoRewetEditViewModel
            {
                TestSheetId    = testSheetId,
                TestValueId    = -1,
                ProductionCode = TestServiceHelper.CreateProductionCode(testSheet),
                NoteCodes      = errorCodes,
                Notes          = new List <TestNote>()
            };

            var oldTestValue = testSheet.TestValues.Where(t => t.TestValueType == TestValueType.Single)
                               .ToList()
                               .LastOrDefault();

            if (oldTestValue == null)
            {
                return(viewModel);
            }
            viewModel.TestPerson         = oldTestValue.LastEditedPerson;
            viewModel.ProductionCodeDay  = oldTestValue.DayInYearOfArticleCreation;
            viewModel.ProductionCodeTime = oldTestValue.IncontinencePadTestValue.IncontinencePadTime;
            viewModel.ExpireMonth        = oldTestValue.IncontinencePadTestValue.ExpireMonth;
            viewModel.ExpireYear         = oldTestValue.IncontinencePadTestValue.ExpireYear;

            return(viewModel);
        }
        /// <summary>
        ///     Creates an new TestValue from the view model
        /// </summary>
        /// <param name="viewModel">the data from the view</param>
        /// <returns>The created test value</returns>
        public TestValue SaveNewRewetTest(InkoRewetEditViewModel viewModel)
        {
            var testValue = TestServiceHelper.CreateNewTestValue(viewModel.TestSheetId, viewModel.TestPerson, viewModel.ProductionCodeDay, viewModel.Notes);

            testValue.ArticleTestType = ArticleType.IncontinencePad;

            var incontinencePadTestValue = new IncontinencePadTestValue
            {
                IncontinencePadTime = viewModel.ProductionCodeTime,
                ExpireMonth         = viewModel.ExpireMonth,
                ExpireYear          = viewModel.ExpireYear,
                RewetFreeDryValue   = viewModel.FPDry,
                RewetFreeWetValue   = viewModel.FPWet,
                TestType            = TestTypeIncontinencePad.RewetFree
            };

            incontinencePadTestValue           = CalculateInkoRewetValues(incontinencePadTestValue, viewModel.TestSheetId);
            testValue.IncontinencePadTestValue = incontinencePadTestValue;

            TestBll.SaveNewTestValue(testValue);
            return(testValue);
        }
Exemplo n.º 8
0
        public ActionResult Save(InkoRewetEditViewModel viewModel)
        {
            var savedModel = InkoRewetService.Save(viewModel);

            return(RedirectToAction("Edit", "LaborCreatorInko", new { area = "Labor", id = savedModel.TestSheetId }));
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Gets a new InkoRewetEditViewModel
        /// </summary>
        /// <param name="rewetTestId">The Id of the Inko rewet test which will be edited</param>
        /// <returns>The InkoRewetEditViewModel</returns>
        public InkoRewetEditViewModel GetInkoRewetEditViewModel(Int32 rewetTestId)
        {
            var testValue = TestBll.GetTestValue(rewetTestId);

            if (testValue.IsNull())
            {
                Logger.Error("TestValue mit id " + rewetTestId + "existiert nicht in DB!");
                return(null);
            }
            var incontinencePadTestValue = testValue.IncontinencePadTestValue;

            if (incontinencePadTestValue.IsNull())
            {
                Logger.Error("IncontinencePadTestValue mit id " + testValue.TestValueId + "existiert nicht in DB!");
                return(null);
            }
            if (incontinencePadTestValue.TestType != TestTypeIncontinencePad.RewetFree)
            {
                Logger.Error("Requestet test was not an InkoRewet Test. Id " + testValue.TestValueId);
                return(null);
            }
            var testSheet = testValue.TestSheet;

            if (testSheet.IsNull())
            {
                Logger.Error("TestBlatt mit id " + testValue.TestSheetId + "existiert nicht in DB!");
                return(null);
            }
            var notes      = testValue.TestValueNote;
            var errors     = TestBll.GetAllNoteCodes();
            var errorCodes = errors.Select(error => new ErrorCode {
                ErrorId = error.ErrorId, Name = error.ErrorCode + " - " + error.Value
            })
                             .ToList();

            if (notes.IsNull())
            {
                notes = new List <TestValueNote>();
            }
            var testNotes = notes.Select(note => new TestNote {
                Id = note.TestValueNoteId, ErrorCodeId = note.ErrorId, Message = note.Message
            })
                            .ToList();

            var viewModel = new InkoRewetEditViewModel
            {
                TestValueId        = rewetTestId,
                TestSheetId        = testValue.TestSheetId,
                TestPerson         = testValue.LastEditedPerson,
                ProductionCode     = TestServiceHelper.CreateProductionCode(testSheet),
                ProductionCodeDay  = testValue.DayInYearOfArticleCreation,
                ProductionCodeTime = incontinencePadTestValue.IncontinencePadTime,
                ExpireMonth        = incontinencePadTestValue.ExpireMonth,
                ExpireYear         = incontinencePadTestValue.ExpireYear,
                FPDry     = incontinencePadTestValue.RewetFreeDryValue,
                FPWet     = incontinencePadTestValue.RewetFreeWetValue,
                Notes     = testNotes,
                NoteCodes = errorCodes
            };

            return(viewModel);
        }