Пример #1
0
        private async Task <LimpingTest> AddDefaultDataForAnalysis(LimpingDbContext context)
        {
            var analysis = new TestAnalysis
            {
                Id              = Guid.NewGuid(),
                Description     = "Something",
                EndValue        = 1.5,
                LimpingSeverity = LimpingSeverityEnum.Medium,
            };
            var appUser = context.AppUsers.Add(new AppUser
            {
                Id           = "1",
                UserName     = "******",
                LimpingTests = new List <LimpingTest>(),
                Email        = "f",
            }).Entity;
            var limpingTest = context.LimpingTests.Add(new LimpingTest
            {
                AppUserId    = appUser.Id,
                Date         = DateTime.Now,
                TestAnalysis = analysis,
                TestData     = "{numbers: [1, 2, 3]}"
            }).Entity;
            await context.LimpingTests.AddAsync(limpingTest);

            await context.SaveChangesAsync();

            context.Entry(limpingTest).State = EntityState.Detached;
            context.Entry(appUser).State     = EntityState.Detached;
            context.Entry(analysis).State    = EntityState.Detached;
            return(limpingTest);
        }
Пример #2
0
        public async Task ReplaceTestAnalysis(Guid testId, TestAnalysis newTest)
        {
            var test = await _context.LimpingTests.Include(x => x.TestAnalysis).SingleAsync(x => x.Id == testId);

            if (test.TestAnalysis != null)
            {
                _context.TestAnalyses.Remove(test.TestAnalysis);
            }

            test.TestAnalysis          = newTest;
            _context.Entry(test).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }
Пример #3
0
        public async Task <AppUser> Edit(AppUser user)
        {
            _context.Entry(user).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(user);
        }
Пример #4
0
        public async Task <LimpingTest> EditTest(Guid testId, string testData, TestAnalysis testAnalysis)
        {
            var limpingTest = await _context.LimpingTests.FindAsync(testId);

            _context.Entry(limpingTest).State = EntityState.Modified;
            limpingTest.TestData = testData;
            if (testAnalysis != null)
            {
                _context.Entry(limpingTest).Reference(x => x.TestAnalysis).Load();
                var oldAnalysis = limpingTest.TestAnalysis;
                _context.Entry(oldAnalysis).State = EntityState.Modified;
                oldAnalysis.Description           = testAnalysis.Description;
                oldAnalysis.EndValue        = testAnalysis.EndValue;
                oldAnalysis.LimpingSeverity = testAnalysis.LimpingSeverity;
            }
            limpingTest.Date = DateTime.Now;
            await _context.SaveChangesAsync();

            return(limpingTest);
        }
Пример #5
0
        public async Task <IActionResult> Delete([FromRoute] Guid limpingTestId)
        {
            var exists = await _context.LimpingTests.AnyAsync(lt => lt.Id == limpingTestId);

            if (!exists)
            {
                return(NotFound());
            }

            var limpingTest = await _limpingTestsService.GetById(limpingTestId);

            _context.Entry(limpingTest).State = EntityState.Detached;
            await _limpingTestsService.DeleteTest(limpingTestId);

            var response = new HALResponse(null).AddLinks(
                LinkGenerator.LimpingTests.Delete(limpingTestId.ToString(), "self"),
                LinkGenerator.LimpingTests.GetAll(),
                LinkGenerator.LimpingTests.GetForUser(limpingTest.AppUserId),
                LinkGenerator.Users.GetSingle(limpingTest.AppUserId)
                );

            return(Ok(response));
        }