public async Task <CustomEntity> Update(Guid id, CustomDto customDto)
        {
            if (customDto != null)
            {
                try
                {
                    var entity = await _customRepository.GetById(id);

                    entity.Username = customDto.Username;
                    entity.Password = customDto.Password;
                    entity.TestInt  = customDto.TestInt;

                    //Update
                    _customRepository.Update(entity);

                    await _uow.Commit();

                    return(entity);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                return(null);
            }
        }
        public async Task <ActionResult <CustomEntity> > Put(Guid id, [FromBody] CustomDto value)
        {
            try
            {
                var entity = await _customTestService.Update(id, value);

                return(Ok(entity));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static CustomEntity ToEntity(this CustomDto entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new CustomEntity
            {
                Username = entity.Username ?? new string(""),
                Password = entity.Password ?? new string(""),
                TestInt = entity.TestInt
            });
        }
        public async Task <CustomEntity> Create(CustomDto customDto)
        {
            try
            {
                var entity = customDto.ToEntity();

                _customRepository.Add(entity);

                // it will be null
                var testEntity = await _customRepository.GetById(entity.Id);

                // If everything is ok then:
                await _uow.Commit();

                // The product will be added only after commit
                testEntity = await _customRepository.GetById(entity.Id);

                return(testEntity);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 5
0
 public void Post([FromBody] CustomDto value)
 {
 }
Ejemplo n.º 6
0
 public void SetCustomDto(CustomDto customDto) => CustomDtoService.customDto = customDto;