コード例 #1
0
        public async Task <ActionResult> Store([FromBody] SubjectViewModel model)
        {
            await ValidateRequestAsync(model);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var subject = model.MapEntity(_mapper, CurrentUserId);

            subject = await _subjectsService.CreateAsync(subject);

            return(Ok(subject.Id));
        }
コード例 #2
0
        public async Task <ActionResult> Update(int id, [FromBody] SubjectViewModel model)
        {
            var existingEntity = _subjectsService.GetById(id);

            if (existingEntity == null)
            {
                return(NotFound());
            }

            await ValidateRequestAsync(model);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var subject = model.MapEntity(_mapper, CurrentUserId);

            await _subjectsService.UpdateAsync(existingEntity, subject);

            return(Ok());
        }