Beispiel #1
0
        public async Task <ActionResult> UpdateAsync([FromBody] ModuleInfoDTO moduleInfo, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowUpdate)
            {
                return(ValidationProblem());
            }
            var specFilter = new ModuleInfoFilterSpecification(int.Parse(moduleInfo.Id), true);
            var rowCount   = await _moduleInfoService.CountAsync(specFilter, cancellationToken);

            if (rowCount == 0)
            {
                throw new EntityNotFoundException(nameof(ModuleInfo), moduleInfo.Id);
            }

            // bind to old item


            var objItem = _mapper.Map <ModuleInfo>(moduleInfo);

            // untuk data yang mereference object, perlu di set null agar tidak insert sebagai data baru
            CleanReferenceObject(objItem);

            var result = await _moduleInfoService.UpdateAsync(objItem, cancellationToken);

            if (!result)
            {
                AssignToModelState(_moduleInfoService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(GetIdAsync), new { id = objItem.Id }, null));
        }
Beispiel #2
0
        public async Task <ActionResult> UpdateDraftAsync(int id, [FromBody] ModuleInfoDTO moduleInfoDto, CancellationToken cancellationToken = default)
        {
            InitUserInfo();
            if (!AllowCreate && !AllowUpdate)
            {
                return(ValidationProblem());
            }
            var specFilter = new ModuleInfoFilterSpecification(int.Parse(moduleInfoDto.Id), true);
            var rowCount   = await _moduleInfoService.CountAsync(specFilter, cancellationToken);

            if (rowCount == 0)
            {
                throw new EntityNotFoundException(nameof(ModuleInfo), moduleInfoDto.Id);
            }

            var moduleInfo = _mapper.Map <ModuleInfo>(moduleInfoDto);
            var result     = await _moduleInfoService.PatchDraft(moduleInfo, cancellationToken);

            if (!result)
            {
                AssignToModelState(_moduleInfoService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(GetIdAsync), new { id = id }, null));
        }
Beispiel #3
0
        public async Task <ActionResult> CreateAsync([FromBody] ModuleInfoDTO moduleInfo, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowCreate)
            {
                return(ValidationProblem());
            }
            // remove temporary id (if any)

            var newItem = _mapper.Map <ModuleInfo>(moduleInfo);

            // untuk data yang mereference object, perlu di set null agar tidak insert sebagai data baru
            CleanReferenceObject(newItem);

            newItem = await _moduleInfoService.AddAsync(newItem, cancellationToken);

            if (newItem == null)
            {
                AssignToModelState(_moduleInfoService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(GetIdAsync), new { id = newItem.Id }, null));
        }