Example #1
0
        public async Task <ActionRes> CreateOrUpdateAsync([FromBody] CreateBookUserDto dto)
        {
            var bookUserOutput = await _bookUserAppService.GetByOpenidAsync(dto.Openid);

            if (bookUserOutput == null)
            {
                await _bookUserAppService.CreateAsync(dto);
            }
            else
            {
                await _bookUserAppService.UpdateAsync(ObjectMapper.Map <UpdateBookUserDto>(bookUserOutput));
            }

            return(ActionRes.Success());
        }
Example #2
0
        public async Task <ActionRes> CreateOrUpdateAsync([FromBody] CreateBookUserDto dto)
        {
            //临时方案,只适合单机部署的站点使用。如果是分布式,请用redis分布式并发锁等技术
            lock (lockobj)
            {
                var bookUserOutput = _bookUserAppService.GetByOpenidAsync(dto.Openid).Result;

                if (bookUserOutput == null)
                {
                    _bookUserAppService.CreateAsync(dto).Wait();
                }
                else
                {
                    _bookUserAppService.UpdateAsync(ObjectMapper.Map <UpdateBookUserDto>(bookUserOutput)).Wait();
                }
            }

            return(ActionRes.Success());
        }