Beispiel #1
0
        public async Task AddAsync_AddEntity()
        {
            // Arrange
            var expectedCount = await _context.Consultations.CountAsync();

            // Act
            await _consultationService.AddAsync(new ConsultationDTO { Id = 3, SubjectId = 1 });

            var resultCount = await _context.Consultations.CountAsync();

            // Assert
            resultCount.Should().Be(expectedCount + 1);
        }
        public async Task <IActionResult> Add([FromBody] ConsultationDTO consultation)
        {
            try
            {
                await _consultationService.AddAsync(consultation);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(CreatedAtAction(nameof(Add), new { consultation.Id }, consultation));
        }
        public async Task <IActionResult> Create([Bind("Date,SubjectId,LecturerId,Id")] ConsultationDTO consultation)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            consultation.LecturerId = userId;

            if (ModelState.IsValid)
            {
                await _service.AddAsync(consultation);

                return(RedirectToAction(nameof(Index)));
            }

            var subjects = await _subjectService.GetAllAsync();

            ViewData["SubjectId"] = new SelectList(subjects, "Id", "Id", consultation.SubjectId);
            return(View(consultation));
        }