コード例 #1
0
ファイル: GuidManager.cs プロジェクト: ketan-gandhi/Projects
        public async Task <GuidDataModel> Update(Guid guid, GuidAPIModel updatedModel)
        {
            if (updatedModel.Guid.HasValue)
            {
                throw new InvalidRequestParameter(Constants.GUID_NOT_UPDATABLE);
            }

            GuidDataModel originalGuid = await _context.GuidList.FindAsync(guid);

            if (originalGuid == null)
            {
                throw new RecordNotFound(Constants.GUID_NOT_FOUND);
            }

            if (updatedModel.Expire.HasValue)
            {
                originalGuid.Expire = updatedModel.Expire.Value;
            }

            if (updatedModel.User != null)
            {
                originalGuid.User = updatedModel.User;
            }

            await _context.SaveChangesAsync();

            if (_cache.Get <GuidDataModel>(guid) != null)
            {
                _cache.Delete(guid);
            }
            _cache.Add <GuidDataModel>(guid, originalGuid);

            return(originalGuid);
        }