Пример #1
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateSubjectRequest request,
                                                      CancellationToken token)
        {
            var command = new CreateSubjectCommand(request.EnSubjectName, request.HeSubjectName);
            await _commandBus.DispatchAsync(command, token);

            return(Ok());
        }
Пример #2
0
        public async Task <IActionResult> Update([FromBody] CreateSubjectRequest request)
        {
            var created = await _subjectService.UpdateSubjectAsync(request.Id, request.Name, request.FormId);

            if (!created)
            {
                return(BadRequest(new { error = "Subject exists" }));
            }

            return(Ok());
        }
Пример #3
0
        public async Task <ActionResult> Create(CreateSubjectRequest model)
        {
            if (ModelState.IsValid)
            {
                model.UserId = GetCurrentUserId();
                await _subjectAdminService.CreateSubjectAsync(model);

                return(RedirectToAction("Index"));
            }
            ViewBag.Title = "Add a new subject";
            return(View(model));
        }
Пример #4
0
        public async Task <IActionResult> Create(CreateSubjectRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _subjectService.CreateSubject(request);

            if (result.IsSuccessed == false)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Пример #5
0
        public async Task CreateSubjectAsync(CreateSubjectRequest model)
        {
            var profile = await _profileSuperAdminService.GetProfileByUserIdAsync(model.UserId);

            Subject subject = new Subject()
            {
                Id            = Guid.NewGuid(),
                Title         = model.Title,
                Created       = DateTime.UtcNow,
                UserProfileId = profile.Id
            };

            UnitOfWork.SubjectRepository.Add(subject);
            await UnitOfWork.SaveChangesAsync();
        }
Пример #6
0
        public async Task <ApiResult <bool> > CreateSubject(CreateSubjectRequest request)
        {
            var subject = new Subject()
            {
                Name            = request.Name,
                Description     = request.Description,
                NumberOfCredits = request.NumberOfCredits,
                Lesson          = request.Lesson,
                DateCreate      = DateTime.UtcNow.AddHours(7),
                DateUpdate      = DateTime.UtcNow.AddHours(7),
            };

            _context.Subjects.Add(subject);
            await _context.SaveChangesAsync();

            return(new ApiSuccessResult <bool>("Tạo thành công"));
        }
        public async Task Insert_Should_Return_Added_Value(string name, string surname, string email)
        {
            //Assert
            var entity = new CreateSubjectRequest {
                Name = name, Surname = surname, Email = email
            };
            //Act
            var result = await _sut.Create(entity) as CreatedResult;

            // Assert
            SubjectRepository.Verify(x => x.Create(It.IsAny <Subject>()), Times.Once);

            var model = (SubjectResponseModel)result.Value;

            Assert.Equal(model.Name, entity.Name);
            Assert.Equal(model.Surname, entity.Surname);
            Assert.Equal(model.Email, entity.Email);
        }
Пример #8
0
        public async Task <IActionResult> Create([FromBody] CreateSubjectRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    _logger.LogWarning(LoggingEvents.INSERT_ITEM, ModelState.ToString());
                    return(BadRequest(ModelState));
                }

                var result = await _service.Create(_mapper.Map <CreateSubjectRequest, Subject>(request));

                return(Created($"{Request.GetUri()}/{result.Name}", _mapper.Map <Subject, SubjectResponseModel>(result)));
            }
            catch (Exception e)
            {
                _logger.LogError(LoggingEvents.INSERT_ITEM, e.ToString());
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.ToString()));
            }
        }
        public async Task <IActionResult> AddAsync(int yearCourseId, CreateSubjectRequest request)
        {
            var apiKey = Request.Headers.FirstOrDefault(h => string.Equals(h.Key, _options.ApiKeyHeaderName, StringComparison.CurrentCultureIgnoreCase))
                         .Value;

            if (yearCourseId != request.YearCourseId)
            {
                return(BadRequest(new ApiResponse
                {
                    Messages = new List <string>
                    {
                        "Year course ID doesn't match!"
                    }
                }));
            }

            var result = await _mediator.Send(new CreateYearCourseSubjectCommand
            {
                YearCourseId = request.YearCourseId,
                Password     = apiKey,
                Name         = request.Name,
                ShortName    = request.ShortName
            });

            if (!result.Succeeded)
            {
                return(StatusCode((int?)result.ErrorType ?? 400, new ApiResponse <int>
                {
                    Messages = result.ErrorMessages
                }));
            }

            return(Ok(new ApiResponse <int>
            {
                Result = result.Output
            }));
        }